Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <stack>
  6. #define MAXN 112345
  7. #define S second
  8. #define $ ios::sync_with_stdio(0);
  9. using namespace std;
  10. typedef pair<char, int> ii;
  11. int main()
  12. {$
  13.     int n , cost, m, j, major, sum;
  14.     string s, ans;
  15.     stack<char> st;
  16.     while(cin>>n>>m && n)
  17.     {
  18.         cin>>s;
  19.         st.push(s[0]);
  20.         for(int i = 1; s[i]; ++i)
  21.         {
  22.             while(!st.empty() && st.top()<s[i] && m)
  23.                 st.pop(), m--;
  24.             st.push(s[i]);
  25.         }
  26.         ans= "";
  27.         while(!st.empty()) ans+=st.top(), st.pop();
  28.         reverse(ans.begin(), ans.end());
  29.  
  30.  
  31.         for(int i = 0; i<(int)ans.size()-m; ++i)
  32.             cout<<ans[i];
  33.         cout<<'\n';
  34.  
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement