Advertisement
Saleh127

CF 435B.cpp

Oct 14th, 2020 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. string a;
  11. ll c,d,e,i,j,k;
  12. cin>>a>>k;
  13.  
  14. for(i=0;i<a.size()-1;i++)
  15. {
  16. c=i;
  17. for(j=i+1;j<a.size() && j-i<=k;j++)
  18. {
  19. if(a[j]>a[c])
  20. {
  21. c=j;
  22. }
  23. }
  24. k-=(c-i);
  25. while(c!=i)
  26. {
  27. swap(a[c],a[c-1]);
  28. c--;
  29. }
  30. }
  31.  
  32. cout<<a<<endl;
  33.  
  34. return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement