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. Visual Studio中添加API断点

    如:添加 PostMessageA 断点 {,,USER32.DLL}_PostMessageA@16 //判断为WM_CLOSE消息*(int*)(esp + 8) == 0x0010

  2. YouCompleteMe

    需要配套的.vimrc :sw:.h与.cpp切换 Issue:YouCompleteMe unavailable no module named future cd .vim/Vundle/YouC ...

  3. hashcode和equals区别

    hashcode:对象的初始地址的整数表示 Java中的对象是JVM在管理,JVM会在她认为合适的时候对对象进行移动,比如,在某些需要整理内存碎片的GC算法下发生的GC.此时,对象的地址会变动,但ha ...

  4. webuploader的一个页面多个上传按钮实例

    借鉴一位大佬的demo  附上他的github地址https://github.com/lishuqi 我把他的cxuploader.js改了不需要预览  直接上传图片后拿到回传地址给img标签显示图 ...

  5. flask第三方插件DBUtils

    django中有强大的ORM支持我们来操作数据库, 但是flask没有提供对数据库的操作, 依然还是需要第三方的支持, 来提高我们的开发效率. 下载DBUtils 使用DBUtils 使用DBUtil ...

  6. 【Spark】Spark核心之弹性分布式数据集RDD

    1. RDD概述 1.1 什么是RDD (1) RDD(Resilient Distributed Dataset)弹性分布式数据集,它是Spark的基本数据抽象,它代表一个不可变.可分区.里面的元素 ...

  7. Hbase系统架构简述

    由于最近要开始深入的学习一下hbase,所以,先大概了解了hbase的基本架构,在此简单的记录一下. Hbase的逻辑视图 Hbase的物理存储 HRegion Table中所有行都按照row key ...

  8. python3 练习题100例 (三)

    题目三:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? #!/usr/bin/env python3 # -*- coding: utf-8 -*- &qu ...

  9. Django时间时区问题

    在django1.4以后,存在两个概念 naive time 与 active time. 简单点讲,naive time就是不带时区的时间,Active time就是带时区的时间. 举例来说,使用d ...

  10. 解决protobuf import路径的问题

    网上关于protobuf import的文章不太详细,有些问题说的不全,比如import时的路径是在哪个目录中搜索的,比如: 我有一个这样的目录结构,我怎么在demo2/protoDemo2.prot ...