Untitled
Anonymous
c_cpp
10/14/2026 9:13 PM
1.2 KB
7
Indexable
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define PI 3.14
using namespace std;
void testCase()
{
int n,k;
string s;
cin>>n>>k>>s;
int freq[26]={};
int remove[26]={};
for(int i=0;i<s.size();i++){
freq[s[i]-'a']++;
}
for(int i=0;i<26;i++){
if(freq[i]<k){
remove[i]=freq[i];
k-=freq[i];
}
else{
remove[i]=k;
k=0;
break;
}
}
for(int i=0;i<s.size();i++){
int c=s[i]-'a';
if(remove[c]>0){
remove[c]--;
}
else{
cout<<s[i];
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
//cin>>t;
while(t--){
testCase();
}
return 0;
}
Editor is loading...
Leave a Comment