You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly kk characters (k≤nk≤n) from the string ss. Polycarp uses the following algorithm kk times:

  • if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
  • if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
  • ...
  • remove the leftmost occurrence of the letter 'z' and stop the algorithm.

This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly kk times, thus removing exactly kk characters.

Help Polycarp find the resulting string.

Input

The first line of input contains two integers nn and kk (1≤k≤n≤4⋅1051≤k≤n≤4⋅105) — the length of the string and the number of letters Polycarp will remove.

The second line contains the string ss consisting of nn lowercase Latin letters.

Output

Print the string that will be obtained from ss after Polycarp removes exactly kkletters using the above algorithm kk times.

If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).

Examples

Input
15 3
cccaabababaccbc
Output
cccbbabaccbc
Input
15 9
cccaabababaccbc
Output
cccccc
Input
1 1
u
Output

题目意思:给你一个含有n个字符的字符串,删除其中的k个字符,按照字典序列删除,即abcdef......,求出删除完成之后的字符串。

方法一:

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
int id;///字符在字符串中的位置
int vis;///是否删除的状态
char ch;///字符
} s[];
char x[];
int my_comp1(node a,node b)///先按照字典序排序升序,字典序相同时按照在字符串位置升序
{
if(a.ch==b.ch)
{
return a.id<b.id;
}
else
{
return a.ch-'a'<b.ch-'a';
}
}
int my_comp2(node a,node b)///再按照在字符串中的位置升序
{
return a.id<b.id;
}
int main()
{
int n,k,i,len;
scanf("%d%d",&n,&k);
scanf("%s",x);
len=strlen(x);
for(i=; i<len; i++)
{
s[i].ch=x[i];
s[i].id=i;
s[i].vis=;
}
sort(s,s+len,my_comp1);
for(i=; i<k; i++)
{
s[i].vis=;
}
sort(s,s+len,my_comp2);
for(i=; i<len; i++)
{
if(s[i].vis==)
{
continue;
}
else
{
printf("%c",s[i].ch);
}
}
printf("\n");
return ;
}

方法二:成批次地按照字典序删除字符,直到删够k个结束,时间复杂度会更低

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[];
char a[]="abcdefghijklmnopqrstuvwxyz";
int main()
{
int n,k;
int i,j;
char ch;
while(scanf("%d%d",&n,&k)!=EOF)
{
getchar();
scanf("%s",s);
j=;
ch=a[j];
while()
{
for(i=; i<n; i++)
{
if(s[i]==ch)
{
s[i]=' ';
k--;
}
if(k==)
{
break;
}
}
ch=a[++j];
if(k==)
{
break;
}
}
for(i=;i<n;i++)
{
if(s[i]!=' ')
{
printf("%c",s[i]);
}
}
}
return ;
}

Alphabetic Removals(模拟水题)的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. POJ 2014:Flow Layout 模拟水题

    Flow Layout Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3091   Accepted: 2148 Descr ...

  3. 模拟水题,查看二维数组是否有一列都为1(POJ2864)

    题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...

  4. UVA 10714 Ants 蚂蚁 贪心+模拟 水题

    题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...

  5. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  6. HDU4287-STL模拟水题

    一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来 ...

  7. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  8. Mishka and Contest(模拟水题)

    Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...

  9. 模拟水题,牛吃草(POJ2459)

    题目链接:http://poj.org/problem?id=2459 题目大意:有C头牛,下面有C行,每头牛放进草地的时间,每天吃一个草,总共有F1个草,想要在第D的时候,草地只剩下F2个草. 解题 ...

随机推荐

  1. 用RestTemplate调取接口,取得返回数据,携带header,动态拼接url ,动态参数

    记录我自己的工作 get 请求  ,携带 请求头 header (token) url 根据参数 动态拼接 参数   放入 map  动态拼接 private String lclUrl = &quo ...

  2. 高级同步器:可重用的同步屏障Phaser

    引自:https://shift-alt-ctrl.iteye.com/blog/2302923 在JAVA 1.7引入了一个新的并发API:Phaser,一个可重用的同步barrier.在此前,JA ...

  3. javascript 时间倒计时效果

    <div id="divdown1"></div> <script language="javascript" type=&quo ...

  4. 配置一个nginx反向代理&负载均衡服务器

    一.基本信息 系统(L):CentOS 6.9 #下载地址:http://mirrors.sohu.com 反代&负载均衡(N):NGINX 1.14.0 #下载地址:http://nginx ...

  5. vim ,vi总是卡死,终于找到原因了。

    玩了这么多年linux 居然不知道这个..特此记录. 使用vim时,如果你不小心按了 Ctrl + s后,你会发现不能输入任何东西了,像死掉了一般,其实vim并没有死掉,这时vim只是停止向终端输出而 ...

  6. Java线程状态图

    嘤,先盗图一张,后面再补充描述!

  7. Python学习手册之数据封装、类方法、静态方法和属性函数

    在上一篇文章中,我们介绍了 Python 的内部方法.操作符重载和对象生命周期,现在我们介绍 Python 的数据封装.类方法.静态方法和属性函数.查看上一篇文章请点击:https://www.cnb ...

  8. C语言Windows程序开发—MessageBox函数介绍【第01天】

    (一)MessageBox函数的参数介绍: int MessageBox ( HWND hWnd, //弹出MessageBox对话框所属的窗口句柄 LPCTSTR lpText, //指向Messa ...

  9. 网易云音乐API

    网易云音乐API使用 封装了一些api调用 ZZRRegion/StNetease

  10. Apache Tomcat 8.5 安全配置与高并发优化

    通常我们在生产环境中,Tomcat的默认配置显然不能满足我们的产品需求,所以很多时候都需要对Tomcat的配置进行调优,以下综合我自己的经验来配置 Tomcat 安全与优化情况,如果你有更好的方案,请 ...