题目链接:

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 kkcharacters.

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 kk letters 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

题目大意:就是给你一个字符串,要求你去掉k个字符,去掉的规则就是从a开始,如果有a,从a开始去,如果a没有了就从b开始,一次次的递推。

思路:一开始,我是打算一个一个的去,然后一直循环到0结束。然后忘记了看时间复杂度,如果按照我那个计算的话,时间复杂度是8*10 的十次方,这玩意。。。。肯定超时啊,我还搁那傻了吧唧的一个劲的优化,然后就是4发tle。

比完赛后,问别人有咩有比较好的算法,可以这样来做。直接按26个英文按时逐个递减,剪完a再减b,依次往下进行,这样的话时间复杂度就大大的降低了。

代码如下:

#include<iostream>#include<string>#include<cstring>#include<map>#include<cmath>using namespace std;map<char,int >wakaka;bool Exit[400005];int main(){ int n,t; cin>>n>>t; string s; cin>>s; memset(Exit,false,sizeof(Exit)); for(int i=0; i<n; i++) { wakaka[s[i]]++; } int temp=-1; while(t) { temp++; char str=char(temp+97); if(wakaka[str]==0)continue; for(int i=0; i<s.length(); i++) { if(t==0)break; if(s[i]==str&&Exit[i]==false) { Exit[i]=true; t--; } } } for(int i=0; i<s.length(); i++) { if(Exit[i]==false)cout<<s[i]; } cout<<endl; return 0;}

C - Alphabetic Removals的更多相关文章

  1. code forces 999C Alphabetic Removals

    C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. CF999C Alphabetic Removals 思维 第六道 水题

    Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. CodeForces - 999C Alphabetic Removals

    C - Alphabetic Removals ≤k≤n≤4⋅105) - the length of the string and the number of letters Polycarp wi ...

  4. Alphabetic Removals(模拟水题)

    You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly ...

  5. CF999C Alphabetic Removals 题解

    Content 给定一个长度为 \(n\) 的仅含小写字母的字符串,执行 \(k\) 次如下操作: 如果字符串中有 a 这个字母,删除从左往右第一个 a,并结束操作,否则继续操作: 如果字符串中有 b ...

  6. CoderForces999C-Alphabetic Removals

    C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. Codeforces Round #490 (Div. 3)

    感觉现在\(div3\)的题目也不错啊? 或许是我变辣鸡了吧....... 代码戳这里 A. Mishka and Contes 从两边去掉所有\(≤k\)的数,统计剩余个数即可 B. Reversi ...

  8. [Codeforces]Codeforces Round #490 (Div. 3)

    Mishka and Contest #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JU ...

  9. [codeforces] 暑期训练之打卡题(三)

    每个标题都做了题目原网址的超链接 Day21<Alphabetic Removals> 题意: 给定一个字符串,要求按照字典序按照出现的前后顺序删除 k 个字母 题解: 记录字符串中各个字 ...

随机推荐

  1. tail 命令只查看日志中的关键字所在行信息

    tail -f info_log-2019-04-20.log |grep 要查询的关键字

  2. coockie 和 session

    一.Cookie Cookie的数据是由客户端来保存和携带的,所以称之为客户端技术. 1.属性: name:名称不能唯一确定一个Cookie.路径可能不同. value:不能存中文. path:默认值 ...

  3. try语句的使用

    C语言里try是一个语句或函数.其作用是是抛出错误用. 将有可能产生错误的语句括在一起,放入try语句块.如果在try语句块中发生异常,FlashPlayer会创建一个错误对象,并将该Error对象派 ...

  4. python学习笔记:python异常的调用原理

    因为错误是class,捕获一个错误就是捕获到该class的一个实例.因此,错误并不是凭空产生的,而是有意创建并抛出的.Python的内置函数会抛出很多类型的错误,我们自己编写的函数也可以抛出错误. h ...

  5. 随机数Random

    掷骰子10次,统计1.2出现的次数 public static void Main(string[] args) { ,a2=; Random random=new Random();//创建随机数对 ...

  6. node(基础)_node.js中的http服务以及模板引擎的渲染

    一.前言 本节的内容主要涉及: 1.node.js中http服务 2.node.js中fs服务 3.node.js中模板引擎的渲染 4.利用上面几点模拟apache服务器 二.知识 1.node.js ...

  7. Mac 软件专题之:OS X Yosemite 精彩应用软件推荐

    目前,很多软件都已经发布了针对Yosemite系统的版本,今天和大家分享专题:「OS X Yosemite 精彩应用」,主要分享适配Yosemite系统全新的扁平化界面和新功能的软件,但要知道未在此专 ...

  8. Mac 软件专题:高效率工作和学习工具软件推荐

    今天和大家分享软件专题:「高效率工作和学习工具」,简而言之就是提高你工作和学习效率的软件,这对于要天天使用Mac工作或学习的人来说太有帮助了,这里主要分享大家平时经常用的一些,欢迎留言补充. 本文图片 ...

  9. 10款 Mac 经典原型设计开发软件推荐

    在Mac上有大量强大的开发和设计工具,今天和大家推荐10款Mac上的经典原型设计开发工具,原型设计工具是开发者必备的一款工具,无论是网站开发还是移动APP开发,都需要在前期进行严格细致的原型设计,才能 ...

  10. 手把手教你通过Ambari新建Hadoop集群图解案例

    手把手教你通过Ambari新建Hadoop集群图解案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 登陆系统之后,会看到Ambari空空如也的欢迎界面,接下来我们就需要介绍如何通 ...