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. 【CodeForces 129 B】Students and Shoelaces(拓扑排序)

    Anna and Maria are in charge of the math club for junior students. When the club gathers together, t ...

  2. MySQL语句整理(二)

    数据库操作前的准备 -- 创建数据库 -- create database python_test_1 charset=utf8; -- 使用数据库 -- use python_test_1; -- ...

  3. SpringBoot整合Swagger2以及生产环境的安全问题处理

    1.创建springboot项目 https://www.cnblogs.com/i-tao/p/8878562.html 这里我们使用多环境配置: application-dev.yml(开发环境) ...

  4. 02JavaScript用法

    前言: 介绍一下javascript的最基础语法规范和用法. HTML 中的脚本必须位于 <script> 与 </script> 标签之间. 脚本可被放置在 HTML 页面的 ...

  5. ES6 开发规范-最佳实践

    ES6 开发规范(最佳实践) 本文为开发规范,收集方便日后查看. [开发规范]https://blog.csdn.net/zzzkk2009/article/details/53171058?utm_ ...

  6. Kaggle比赛总结

    做完 Kaggle 比赛已经快五个月了,今天来总结一下,为秋招做个准备. 题目要求:根据主办方提供的超过 4 天约 2 亿次的点击数据,建立预测模型预测用户是否会在点击移动应用广告后下载应用程序. 数 ...

  7. python学习笔记(3)---cookie & session

    一.cookie & session 1.cookie: cookie 就是由服务器发送给客户端的特殊信息,而这些信息以文本的方式存放在客户端,然后客户端每次向服务器发送请求都会带上这些特殊信 ...

  8. mysql 几种搜索引擎的比较

    mysql中常见的数据库引擎之间的比较  转载自 深入浅出mysql数据库 MySQL5.5以后默认使用InnoDB存储引擎,其中InnoDB和BDB提供事务安全表,其它存储引擎都是非事务安全表. 若 ...

  9. 常用的go语言IDE对比

    Go语言目前已经在开发者中越发的流行,自然很多人都在寻找合适的IDE来实现代码语法高亮.自动补全以及其他编辑特性. 下面就几种常用的IDE进行对比介绍: 1. Sublime text 这个文本编辑器 ...

  10. Dijkstra算法堆优化(vector建图)

    #include<iostream> #include<algorithm> #include<string.h> #include<stdio.h> ...