A15224 | Not a Cheap String
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let $s$ be a string of lowercase Latin letters. Its price is the sum of the indices of letters (an integer between 1 and 26) that are included in it. For example, the price of the string abca is $1+2+3+1=7$ .
The string $w$ and the integer $p$ are given. Remove the minimal number of letters from $w$ so that its price becomes less than or equal to $p$ and print the resulting string. Note that the resulting string may be empty. You can delete arbitrary letters, they do not have to go in a row. If the price of a given string $w$ is less than or equal to $p$ , then nothing needs to be deleted and $w$ must be output.
Note that when you delete a letter from $w$ , the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst.
The string $w$ and the integer $p$ are given. Remove the minimal number of letters from $w$ so that its price becomes less than or equal to $p$ and print the resulting string. Note that the resulting string may be empty. You can delete arbitrary letters, they do not have to go in a row. If the price of a given string $w$ is less than or equal to $p$ , then nothing needs to be deleted and $w$ must be output.
Note that when you delete a letter from $w$ , the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst.
输入格式
The first line of input contains an integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases in the test. The following are descriptions of $t$ test cases.
Each case consists of two lines.
The first of them is the string $w$ , it is non-empty and consists of lowercase Latin letters. Its length does not exceed $2\cdot10^5$ .
The second line contains an integer $p$ ( $1 \le p \le 5\,200\,000$ ).
It is guaranteed that the sum of string lengths $w$ over all test cases does not exceed $2 \cdot 10^5$ .
Each case consists of two lines.
The first of them is the string $w$ , it is non-empty and consists of lowercase Latin letters. Its length does not exceed $2\cdot10^5$ .
The second line contains an integer $p$ ( $1 \le p \le 5\,200\,000$ ).
It is guaranteed that the sum of string lengths $w$ over all test cases does not exceed $2 \cdot 10^5$ .
输出格式
Output exactly $t$ rows, the $i$ -th of them should contain the answer to the $i$ -th set of input data. Print the longest string that is obtained from $w$ by deleting letters such that its price is less or equal to $p$ . If there are several answers, then output any of them.
Note that the empty string — is one of the possible answers. In this case, just output an empty string.
Note that the empty string — is one of the possible answers. In this case, just output an empty string.
输入输出样例
输入 #1
5 abca 2 abca 6 codeforces 1 codeforces 10 codeforces 100
输出 #1
aa abc cdc codeforces
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted