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
15 3
cccaabababaccbc
Output
cccbbabaccbc
Input
15 9
cccaabababaccbc
Output
cccccc
Input
1 1
u
Output
题目大意:先输入一个字符串长度,再输入一个要删除的字符数量,删除规则是按照字母表的顺序删,先删a再删b再删c…。对于同一个字母先删最左边的。

#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <queue>
#include <cstdio>
#include <string>
#include <string.h>
#include <math.h>
#define N 400010
using namespace std;
int main()
{int n,k;cin>>n>>k;char s[N],ch='a';scanf("%s",s);int j=0;while(1){for(int i=0; i<n; i++){if(s[i]==ch){s[i]=' ';k--;}if(k==0){break;}}ch=ch+1;if(k==0){break;}}for(int i=0;i<n;i++){if(s[i]!=' ')cout<<s[i];}return 0;
}

Alphabetic Removals(水题)相关推荐

  1. 水题/poj 1852 Ants

    1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...

  2. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

  3. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  4. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

  5. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  6. HDU2568 前进【水题】

    前进 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  7. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  8. NUC1312 Sum【水题+数学题】

    Sum 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 认为自然数是从1-N.将每个数和+或-联系起来,然后计算这个表达式的值我们得到一个和S.这个问题 ...

  9. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

  10. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

最新文章

  1. 程序员的量化交易之路(25)--Cointrader之MarketData市场数据实体(12)
  2. atomikos mysql,记一次 Atomikos 分布式事务的使用
  3. centos 实现ssh远程连接docker
  4. 结构体03:结构体指针
  5. 30天自制操作系统之叠加处理
  6. linux如何卸载金山安全终端,卸载和释放-文档中心-金山云
  7. 普莱得电器IPO过会:拟募资5.6亿 为杨伟明及韩挺两家族控制
  8. 各大学习平台资源整合【网站篇一】
  9. 从逻辑功能上看 可以把计算机网络分成,从逻辑功能上看,可以把计算机网络分成通信子网和资源子网。...
  10. UE5 IK重定向并修改人物姿势
  11. android+apk+自动安装,Android版本更新下载apk自动安装的方法
  12. 【技术干货】跨境茶话会第4期丨响应式编程的应用
  13. 高通QCC302x,QCC512X,QCC303X完成智能硬件开发目录
  14. 左连接,右连接与自然连接语法以及注意点
  15. LPTSTR、LPCSTR、LPCTSTR、LPSTR的来源及意义
  16. 前端性能测试 WebPagetest功能
  17. python爬取链家新房_Python爬虫项目--爬取链家热门城市新房
  18. BMZCTF:个人所得税
  19. jQuery幻灯片带缩略图平移滑动焦点图
  20. Javaweb开发问题总结

热门文章

  1. Statement cancelled due to timeout or client request报错
  2. html插入cad,cad插件有哪些
  3. 联想昭阳e43l笔记本配置
  4. 青年志愿者演讲稿范⽂5篇
  5. 【业务安全-01】业务安全概述及测试流程
  6. 通过远程PHP远程调用ZABBIX接口获取数据
  7. 前端程序员从菜鸟到大神必学的七本前端书籍
  8. SegmentFault 技术圈上线,快来找寻你的圈中好友
  9. Windows学习总结(12)——Windows 10系统开始运行-cmd命令大全
  10. 数据分析笔试题|美团点评2020校招