Advertisement
Sunt_tare

Untitled

Dec 15th, 2020
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int CMAX = 2e5+15;
  6. int n, k , misc = 0;
  7. char s[CMAX];
  8.  
  9. int main()
  10. {
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13. cout.tie(NULL);
  14. cin >> n >> k;
  15. for(int i=0;i<=n-1;i++)
  16. {
  17. cin >> s[i];
  18. if(i!=0&&misc<k)
  19. {
  20. while(s[i]>s[i-1]&&misc<k&&i>0)
  21. {
  22. s[i-1] = s[i];
  23. i--;
  24. n--;
  25. misc++;
  26. }
  27. }
  28. }
  29. while(misc<k)
  30. {
  31. n--;
  32. misc++;
  33. }
  34. s[n] = '\0';
  35. //vezi ca esti cu o pozitie in spate i-1
  36. cout << s;
  37. return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement