问题描述:

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

问题分析:

从a到z顺序删除,一直到删除了k个字符为止。输出删除后的字符。

AC代码:

#include <iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
using namespace std;const int N = 400005;int main(){ios::sync_with_stdio(false);cin.tie(0);int n,k;string s;cin>>n>>k>>s;int flag[N];memset(flag,1,sizeof(flag));for(int i = 0;i < 26;i++){for(int j = 0;j < s.size();j++){//从a开始删除 if(s[j] == 'a'+i && k > 0){k--;//标记已经删除了的字符 flag[j] = 0;}}}for(int i = 0;i < s.size();i++){if(flag[i]){cout<<s[i];}}cout<<endl;return 0;
}

Alphabetic Removals相关推荐

  1. CoderForces999C-Alphabetic Removals

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

  2. Multimap的遍历和删除(很重要)

    c++STL容器中Multimap可允许重复键值元素插入容器,但在遍历的时候出现了一些问题.今天要把他解决掉 第一元素是键值,不能修改.第二元素是实值,可以修改. 键值key与元素value的映照关系 ...

  3. Codeforces Round #490 (Div. 3)【完结】

    2022.3.3 题单地址:https://codeforces.com/contest/999 目录 A. Mishka and Contest[模拟] B. Reversing Encryptio ...

  4. Codeforces Round #490 (Div. 3)

    GET reverse() ve.pop_back() ve.back() A. Mishka and Contest 题意 给定一个序列表示题目的难度和Mishka的能力,问Mishka能解决几道问 ...

  5. 字符串处理 —— 模拟与暴力

    [概述] 在某些题目中,需要对字符串进行处理,不需要很复杂的算法,只需要按照题意进行模拟或暴力枚举即可得出答案. [例题] 1.简单模拟 Minimum Ternary String(CF-1009B ...

  6. 周总结2022.1.17-2022.1.23

    1.17 Luogu P3384 [模板]轻重链剖分/树链剖分 学习了树链剖分(Lint-cut Tree)! 虽然之前也有看过,但是今天是第一次自己动手写.学完之后,感觉是一个非常巧妙的东西.树链剖 ...

  7. python字符串基本形式_python字符串常用方式

    class str(basestring): """ str(object='') -> string Return a nice string represent ...

  8. Linux文件分割与合并:splitcat(转载)

    转自:http://os.51cto.com/art/201104/255359.htm Linux下文件分割可以通过split命令来实现,而用cat进行文件合并.而分割可以指定按行数分割和安大小分割 ...

  9. ctypealpha php_php ctype函数中文翻译和示例

    PHP Ctype扩展是PHP4.2开始就内建的扩展,注意,Ctype系列函数都只有一个字符串类型参数,它们返回布尔值. $str = "0.1123"; //检查字符串所有字符是 ...

  10. Python开发(基础):字符串

    字符串常用方法说明 #!/usr/bin/env python # -*- coding:utf-8 -*- # class str(basestring): #     ""&q ...

最新文章

  1. java与fabric区块链--fabric-ca-server 注册---(3)
  2. 软件测试学java,软件测试学习Java的内存模型
  3. boost::serialization模块测试 auto_ptr 序列化的测试程序
  4. One order OPPORT_H read的学习笔记
  5. JeecgCloud 微服务开发平台-部署文档
  6. Android开发笔记(一百七十八)更安全的数据仓库DataStore
  7. NSD cisco高级路由与交换技术--2014.8.16
  8. c语言多变量传函,控制系统仿真-中国大学mooc-题库零氪
  9. “Stream has already been operated upon or closed” Exception in Java
  10. Python正则(粗略)
  11. java立方根怎么打_计算机上怎么打立方根
  12. 【解决方案】【亲测有效】Windows10离线安装.net3.5
  13. 二、互联网思维之用户思维
  14. html将图片做成书的封面,把照片做成杂志 个人照片制作成报纸、杂志封面效果|封面设计软件[图文教程]...
  15. Python爬取简单网页内容
  16. 【射影几何06】齐次坐标下“点-线”几何表示
  17. vins-fusion代码解读[五] imu在vins里的理解
  18. pyramid框架_Python Pyramid Web框架简介
  19. 甘肃两地发生非洲猪瘟疫情 官方全面禁止泔水喂猪
  20. 【转】程序设计语言中的 一等公民,二等公民,三等公民

热门文章

  1. 64位平台C/C++开发注意事项
  2. 【Go语言】深入浅出chan(各种实例场景+分析)
  3. 计算机网速单位是什么,文件大小和网速的单位
  4. Pandas:分组级的运算和转换--transform和apply
  5. hashcat详细使用教程
  6. 应用统计学考研笔记1:数据整理与抽样
  7. 阿里面试——机器学习岗四个面试案例
  8. Python TimedRotatingFileHandler 修改suffix后无法自动删除文件
  9. 用电视上网——网络电视机顶盒
  10. 2021年江苏省高考成绩排名查询,2021年江苏高考个人成绩排名查询方法及排名查询系统...