Alphabetic Removals
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy
  1. 15 3
    cccaabababaccbc
output

Copy
  1. cccbbabaccbc
input

Copy
  1. 15 9
    cccaabababaccbc
output

Copy
  1. cccccc
input

Copy
  1. 1 1
    u
output

Copy
  1.  

这三天写CF终于一遍过了一道题

题意: 给你n个字符,让你删除k个字符,从a开始删,从左到右,删完k个为止,全部删完输出“nothing”或者不输出

vis数组记录每个字符的个数,然后计算下删k个字符删到那个字符为止,记录下剩余这个字符的数量,将这个字符前面的字符的记录值归0

然后从后往前遍历,遇到vis数组还有值得就加入保存结果得字符串t

最后反着输出字符串t(因为你开始时从后往前遍历的,得到的是倒的字符串)

  1. #include <map>
  2. #include <set>
  3. #include <cmath>
  4. #include <queue>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <string>
  8. #include <cstring>
  9. #include <iostream>
  10. #include <algorithm>
  11. #define debug(a) cout << #a << " " << a << endl
  12. using namespace std;
  13. const int maxn = 1e6 + ;
  14. const int mod = 1e9 + ;
  15. typedef long long ll;
  16. int main(){
  17. std::ios::sync_with_stdio(false);
  18. ll n, k;
  19. while( cin >> n >> k ) {
  20. string s;
  21. cin >> s;
  22. ll vis[] = {}, num = ;
  23. for( ll i = ; i < s.length(); i ++ ) {
  24. vis[s[i]-'a'] ++;
  25. }
  26. for( ll i = ; i <= ; i ++ ) {
  27. num += vis[i];
  28. if( num > k ) {
  29. vis[i] = vis[i] - ( k - ( num - vis[i] ) );
  30. break;
  31. } else {
  32. vis[i] = ;
  33. }
  34. }
  35. string t = "";
  36. for( ll i = s.length()-; i >= ; i -- ) {
  37. if( vis[s[i]-'a'] ) {
  38. t += s[i];
  39. vis[s[i]-'a'] --;
  40. }
  41. }
  42. if( t.length() == ) {
  43. cout << endl;
  44. continue;
  45. }
  46. for( ll i = t.length()-; i >= ; i -- ) {
  47. cout << t[i];
  48. }
  49. cout << endl;
  50. }
  51. return ;
  52. }

CF999C Alphabetic Removals 思维 第六道 水题的更多相关文章

  1. HDU 1284 思维上的水题

    其实如果想出了方法真的好水的说... 然而一开始想了好久都没想出来... 最后看了一下最大数据才32768 可以直接枚举...枚举每个硬币的数量 看看后来能不能凑够n 因为还是怕超时..(虽然只有3乘 ...

  2. GCD LCM UVA - 11388 (思维。。水题)

    两个数的最小公倍数和最大公约数肯定是倍数关系 然后又让求使得a最小  因为 a = m * gcd 令m = 1 时 a取得最小  即gcd 则b = lcm #include <iostrea ...

  3. CF999C Alphabetic Removals 题解

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

  4. HDU 2674 N!Again(数学思维水题)

    题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...

  5. HDOJ/HDU 1256 画8(绞下思维~水题)

    Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一 ...

  6. 2019年华南理工校赛(春季赛)--I--炒股(简单思维水题)

    水题,想想就过了 题目如下: 链接:https://ac.nowcoder.com/acm/contest/625/I来源:牛客网 攒机一时爽,一直攒机一直爽. 沉迷攒机的胡老师很快就发现,他每天只能 ...

  7. Iroha and a Grid AtCoder - 1974(思维水题)

    就是一个组合数水题 偷个图 去掉阴影部分  把整个图看成上下两个矩形 对于上面的矩形求出起点到每个绿点的方案 对于下面的矩形 求出每个绿点到终点的方案 上下两个绿点的方案相乘后相加 就是了 想想为什么 ...

  8. UVa 11636 Hello World! (水题思维)

    题意:给你一个数,让你求需要复制粘贴多少次才能达到这个数. 析:这真是一个水题,相当水,很容易知道每次都翻倍,只要大于等于给定的数就ok了. 代码如下: #include <iostream&g ...

  9. sdut 2163:Identifiers(第二届山东省省赛原题,水题)

    Identifiers Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  Identifier is an important c ...

随机推荐

  1. Python实现批量处理扫描特定目录

    ## 简述在渗透测试中遇到相同CMS站点时,搞定一个站点,相当于拿了一个站群的通用漏洞,所以我们首先需要标注站点的CMS类型,根据要求编写如下脚本 ## 要求1.访问特定目录,如:站点特定 /cmsa ...

  2. 一个项目的SpringCloud微服务改造过程

    SSO是公司一个已经存在了若干年的项目,后端采用SpringMVC.MyBatis,数据库使用MySQL,前端展示使用Freemark.今年,我们对该项目进行了一次革命性的改进,改造成SpringCl ...

  3. 让techempower帮你通讯服务框架的性能

    在编写服务应用框架的时候一般都需要进行性能测试,但自己测试毕竟资源受限所以很难做更高性能上的测试.其实GitHub上有一个项目可以让开发人员提交自己的框架服务代码然后进行一个标准测试:现在已经有上百个 ...

  4. 浏览器输入URL到返回页面的全过程

    [问题描述] 在浏览器输入www.baidu.com,然后,浏览器显示相应的百度页面,这个过程究竟发生了什么呢? [第一步,解析域名,找到主机] 正常情况下,浏览器会缓存DNS一段时间,一般2分钟到3 ...

  5. Mysql 分页order by一个相同字段,发现顺序错乱

    两次分页查询,其中跳过了2个id   select * from jdp_tb_trade  where jdp_modified>='2017-04-24 20:22:01' and jdp_ ...

  6. [实践]activemq安全设置 设置admin的用户名和密码

    (1)打开/opt/app/amq/apache-activemq-5.9.0/conf/jetty.xml 找到 将property name为authenticate的属性value=" ...

  7. LeetCode——540. Single Element in a Sorted Array

    题目:Given a sorted array consisting of only integers where every element appears twice except for one ...

  8. Linux文件及目录管理

    1.Linux文件目录树 /:根目录,linux文件系统的最顶端和入口 bin:存放用户二进制文件(如:ls,cd,mv等),实则/user/bin的硬链接(相当于Windows系统的快捷方式) bo ...

  9. C#之反射、元数据详解

    前言 在本节中主要讲述自定义特性.反射和动态编程.自定义特性允许把自定义元数据与程序元素关联起来.这些元数据是在编译过程中创建的,并嵌入程序集中.反射是一个普通的术语,它描述了在运行过程中检查和处理程 ...

  10. python面向对象初始进阶版 通过一道题带你认识面向对象

    定义一个类 class Person: #公共属性 animal='高级动物' soul='有灵魂' language='语言' def init(self,country,name,sex,age, ...