欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1702D.Not a Cheap String
Not a Cheap String
Let 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 .
The string and the integer are given. Remove the minimal number of letters from so that its price becomes less than or equal to 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 is less than or equal to , then nothing needs to be deleted and must be output.
Note that when you delete a letter from , the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst.
Input
The first line of input contains an integer () — the number of test cases in the test. The following are descriptions of test cases.
Each case consists of two lines.
The first of them is the string , it is non-empty and consists of lowercase Latin letters. Its length does not exceed .
The second line contains an integer ().
It is guaranteed that the sum of string lengths over all test cases does not exceed .
Output
Output exactly rows, the -th of them should contain the answer to the -th set of input data. Print the longest string that is obtained from by deleting letters such that its price is less or equal to . 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.
Samples
5
abca
2
abca
6
codeforces
1
codeforces
10
codeforces
100
aa
abc
cdc
codeforces
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |