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. awk命令用法

    awk:把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各种分析处理,是一个强大的文本分析工具,在对数据分析并生成报告时很有优势. awk有3个不同版本: awk.nawk和gawk, ...

  2. java实现验证码功能主要代码

    package com.baojuan.servlet; import java.awt.Color;import java.awt.Font;import java.awt.Graphics2D;i ...

  3. nginx的docker化部署

    nginx的docker化有一个隐藏的坑,就是其默认的配置目录(/etc/nginx)需要先从容器中拷贝出来. 拉取镜像 docker pull nginx 启动容器 docker run -d -- ...

  4. idea配置SpringBoot热部署之自动Build

    一.pom.xml文件导入所需依赖文件 SpringBoot热部署插件 <dependency> <groupId>org.springframework.boot</g ...

  5. Flask基本介绍

    Fask 1.Flask简介 Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架对于Werkzeug本质是socket服务端,其用于接收http ...

  6. browser-cookies 一个管理cookies的插件,好用

    一.browser-cookies 地址:https://github.com/voltace/browser-cookies 用法 存放cookies是 cookies.set('firstName ...

  7. auto、static、extern

  8. Django中ORM简述

    ORM:对象关系映射(Object Relational Mapping,简称ORM) 作用:根据类生成表结构,将对象.列表的操作转换成对象的SQL语句,将SQL语句查询的结果转换为对象或列表 优点: ...

  9. FPGA烧完程序之后,检测不到网口的

    原因:未给phy芯片添加复位 解决方法:在程序顶部添加一个输出信号output e_reset,使其值一直为高. output e_reset, 'b1;

  10. 版本控制工具——Git的拓展使用

    一.使用Github 通过前面两节已经配置了SSH Key与Github上的相关设置,接下来介绍常用的使用 使用Fork克隆一份到本地仓库 之后可以在自己的仓库克隆一份到本地 git clone gi ...