#include<bits/stdc++.h> #include <iostream> #include <vector> #include <utility> #include <iterator> #include <algorithm> #include <deque> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long N,M ; cin>>N>>M ; string X ; cin>>X ; vector<long long >arr(26,0) ; for(auto i:X){ arr[i-'a']++ ; } int K=0 ; while(1){ if(M==0 ||K==26){ break; } if(arr[K]==0){ K++ ; continue ; } for(long long J=0 ;J<N ;J++){ if(X[J]==K+'a'){ X[J]='1' ; M-- ; arr[K]-- ; break ; } } } for(long long i=0 ;i<N ;i++){ if(X[i]!='1'){ cout<<X[i]; } } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter