CF999C.Alphabetic Removals
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
给你一个由 n 个小写拉丁字母组成的字符串 s。Polycarp 想要从字符串 s 中恰好移除 k 个字符(其中 k≤n)。Polycarp 使用如下算法,共执行 k 次:
- 如果字符串中至少存在一个字母
'a',则移除最左侧的'a'并终止本次算法;否则进入下一项; - 如果字符串中至少存在一个字母
'b',则移除最左侧的'b'并终止本次算法;否则进入下一项; - ...
- 移除最左侧的字母
'z'并终止本次算法。
该算法每次仅从字符串中移除一个字母。Polycarp 恰好执行该算法 k 次,因此总共移除 k 个字符。
请帮助 Polycarp 找出最终得到的字符串。
输入格式
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.
输入的第一行包含两个整数 n 和 k(1≤k≤n≤4⋅105)—— 分别表示字符串的长度以及 Polycarp 将要删除的字母个数。
第二行包含一个由 n 个小写拉丁字母组成的字符串 s。
输出格式
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).
按照上述算法,将字符串 s 经过 Polycarp 恰好 k 次删除操作后得到的字符串输出。
如果最终得到的字符串为空,则不输出任何内容。允许不输出任何内容或仅输出一个空行(换行符)。
输入输出样例
输入#1
15 3 cccaabababaccbc
输出#1
cccbbabaccbc
输入#2
15 9 cccaabababaccbc
输出#2
cccccc
输入#3
1 1 u
输出#3
输入解题思路,AI测评打分。不知道怎么写?