You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k≤n) from the string s. Polycarp uses the following algorithm k 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 k times, thus removing exactly k characters.

Help Polycarp find the resulting string.

Input

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

The second line contains the string s consisting of n lowercase Latin letters.

Output

Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times.

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

Examples

Input 1

  1. cccaabababaccbc

Output 1

  1. cccbbabaccbc

Input 2

  1. cccaabababaccbc

Output 2

  1. cccccc

Input 3

  1. u

Output 3

思路:

类比桶排序,用桶来存字母的个数

代码:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <string>
  5. #include <math.h>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <stack>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <math.h>
  13. const int INF=0x3f3f3f3f;
  14. typedef long long LL;
  15. const int mod=1e9+;
  16. const int maxn=*1e5+;
  17. using namespace std;
  18.  
  19. char str[maxn];
  20. int cnt[];//原来字母的个数
  21. int num[];//处理后字母的个数
  22.  
  23. int main()
  24. {
  25. int n,k;
  26. scanf("%d %d",&n,&k);
  27. getchar();
  28. for(int i=;i<n;i++)
  29. {
  30. scanf("%c",&str[i]);
  31. cnt[str[i]-'a'+]++;
  32. num[str[i]-'a'+]++;
  33. }
  34. str[n]=;
  35. for(int i=;i<=;i++)//从'a'开始进行k次处理
  36. {
  37. while(num[i]&&k)
  38. {
  39. num[i]--;
  40. k--;
  41. }
  42. }
  43. for(int i=;str[i];i++)
  44. {
  45. if(cnt[str[i]-'a'+]>num[str[i]-'a'+])//说明该位置字母已删除
  46. {
  47. cnt[str[i]-'a'+]--;
  48. continue;
  49. }
  50. else //若该位置字母没被删,输出该字母
  51. printf("%c",str[i]);
  52. }
  53. return ;
  54. }
 

CodeForces (字符串从字母a开始删除k个字母)的更多相关文章

  1. codeforces 1038a(找最长的前k个字母出现相同次数的字符串)

    codeforces 1038a You are given a string s of length n, which consists only of the first k letters of ...

  2. C语言:将ss所指字符串中所有下标为奇数位上的字母转换成大写,若不是字母,则不转换。-删除指针p所指字符串中的所有空白字符(包括制表符,回车符,换行符)-在带头结点的单向链表中,查找数据域中值为ch的结点,找到后通过函数值返回该结点在链表中所处的顺序号,

    //将ss所指字符串中所有下标为奇数位上的字母转换成大写,若不是字母,则不转换. #include <stdio.h> #include <string.h> void fun ...

  3. C语言:将ss所指字符串中所有下标为奇数位置的字母转换为大写-将该字符串中的所有字符按ASCII码值升序排序后输出。-将a所指的4*3矩阵第k行的元素与第0行元素交换。

    //函数fun:将ss所指字符串中所有下标为奇数位置的字母转换为大写,若不是字母,则不转换. #include<conio.h> #include<stdio.h> #incl ...

  4. Day_11【集合】扩展案例2_使用普通for循环获取集合中索引为3的元素并打印,统计集合中包含字符串"def"的数量,删除集合中的所有字符串",将集合中每个元素中的小写字母变成大写字母def",

    分析以下需求,并用代码实现 1.定义ArrayList集合,存入多个字符串"abc" "def" "efg" "def" ...

  5. (笔试题)删除K位数字

    题目: 现有一个 n 位数,你需要删除其中的 k 位,请问如何删除才能使得剩下的数最大? 比如当数为 2319274, k=1 时,删去 2 变成 319274 后是可能的最大值. 思路: 1.贪心算 ...

  6. Java-Runoob-高级教程-实例-字符串:03. Java 实例 - 删除字符串中的一个字符

    ylbtech-Java-Runoob-高级教程-实例-字符串:03. Java 实例 - 删除字符串中的一个字符 1.返回顶部 1. Java 实例 - 删除字符串中的一个字符  Java 实例 以 ...

  7. C#根据用户输入字符串,输出大写字母有几个,小写字母有几个

    static void Main(string[] args) { // 根据用户输入字符串,输出大写字母有几个,小写字母有几个. Console.WriteLine("请输入一行英文代码& ...

  8. Day_09【常用API】扩展案例5_获取长度为5的随机字符串,字符串由随机的4个大写英文字母和1个0-9之间(包含0和9)的整数组成

    分析以下需求,并用代码实现 1.定义String getStr(char[] chs)方法 功能描述:获取长度为5的随机字符串,字符串由随机的4个大写英文字母和1个0-9之间(包含0和9)的整数组成 ...

  9. 【LeetCode】1461. 检查一个字符串是否包含所有长度为 K 的二进制子串 Check If a String Contains All Binary Codes of Size K

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计长度为 K 的子串个数 日期 题目地址:https ...

随机推荐

  1. C# 绘制矩形方框读写内存类 cs1.6人物透视例子

     封装的有问题 其中方框可能在别的方向可能 会显示不出来建议不要下载了 抽时间我会用纯c#写一个例子的  其中绘制方框文字和直线调用的外部dll采用DX11(不吃CUP)绘制我封装成了DLL命名为 S ...

  2. c# quartz

    quartz调度核心元素: Scheduler:任务调度器,是实际执行任务调度的控制器.在spring中通过SchedulerFactoryBean封装起来. Trigger:触发器,用于定义任务调度 ...

  3. 7 —— node —— 响应图片

      const http = require('http'); const fs = require('fs'); const server = http.createServer(); server ...

  4. nginx location语法解释

    1.没有修饰符 表示:必须以指定模式开始,如:              默认模式 server { server_name baidu.com; location /abc { …… } } htt ...

  5. windows下移植别人配置好的python环境

    一般来说,我们在windows下配置python环境的时候可能会比较推荐用anaconda,那么有一个比较方便的anaconda环境移植方法,也就是说,如果我已经在windows上安装好了anacon ...

  6. 文献阅读报告 - Social Ways: Learning Multi-Modal Distributions of Pedestrian Trajectories with GANs

    文献引用 Amirian J, Hayet J B, Pettre J. Social Ways: Learning Multi-Modal Distributions of Pedestrian T ...

  7. 8. Redis 持久化对生产环境的灾难恢复的意义

    1.故障发生的时候会怎么样2.如何应对故障的发生 很多同学,自己也看过一些redis的资料和书籍,当然可能也看过一些redis视频课程 所有的资料,其实都会讲解redis持久化,但是有个问题,我到目前 ...

  8. 调试ASP.NET程序

    用VS打开你的项目 从VS中找到"调试"-----"附件到进程",然后选中w3wp.exe,点击附件到进程,然后再发送数据进行调试就可以了

  9. c++程序—三目运算符

    #include<iostream> using namespace std; #include<string> int main() { //三目运算符 ; ; ; c = ...

  10. 【pwnable.kr】bof

    pwnable从入门到放弃,第三题. Download : http://pwnable.kr/bin/bofDownload : http://pwnable.kr/bin/bof.c Runnin ...