0
点赞
收藏
分享

微信扫一扫

codeforces 999C Alphabetic Removals

圣杰 2022-08-08 阅读 74


​​http://www.elijahqi.win/archives/3819​​​
先统计再贪心

最后暴力模拟

#include<bits/stdc++.h>
using namespace std;
const int N=4e5+10;
char s[N],s1[N];int n,k,top,cnt[50];
int main(){
// freopen("c.in","r",stdin);
scanf("%d%d",&n,&k);scanf("%s",s+1);
for (int i=1;i<=n;++i){
++cnt[s[i]-'a'];
}int ed=-1;
for (int i=0;i<26;++i) {
if (k<=cnt[i]) {ed=i;break;}k-=cnt[i];
}
for (int i=1;i<=n;++i){
if (s[i]-'a'<ed) continue;
if (s[i]-'a'==ed&&k) {--k;continue;}
s1[++top]=s[i];
}printf("%s",s1+1);
return 0;
}


举报

相关推荐

0 条评论