CF1702D.Not a Cheap String

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let ss 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=71+2+3+1=7.

The string ww and the integer pp are given. Remove the minimal number of letters from ww so that its price becomes less than or equal to pp 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 ww is less than or equal to pp, then nothing needs to be deleted and ww must be output.

Note that when you delete a letter from ww, the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst.

设 ss 是一个由小写拉丁字母组成的字符串。其价格定义为字符串中所有字母对应序号(整数,范围为 1 到 26)之和。例如,字符串 abca 的价格为 1+2+3+1=71+2+3+1=7。

给定字符串 ww 和整数 pp。请从 ww 中删除最少数量的字母,使得剩余字符串的价格不超过 pp,并输出该结果字符串。注意:结果字符串可以为空。你可以删除任意位置的字母,不要求这些字母在原字符串中连续。若字符串 ww 当前的价格已不超过 pp,则无需删除任何字母,直接输出 ww。

注意:从 ww 中删除字母后,剩余字母的相对顺序保持不变。例如,若从字符串 test 中删除字母 e,则得到 tst。

输入格式

The first line of input contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases in the test. The following are descriptions of tt test cases.

Each case consists of two lines.

The first of them is the string ww, it is non-empty and consists of lowercase Latin letters. Its length does not exceed 2⋅1052\cdot10^5.

The second line contains an integer pp (1≤p≤5 200 0001 \le p \le 5\,200\,000).

It is guaranteed that the sum of string lengths ww over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。接下来是 tt 个测试用例的描述。

每个测试用例由两行组成。

第一行为字符串 ww,它非空且仅由小写拉丁字母组成,其长度不超过 2⋅1052\cdot10^5。

第二行为一个整数 pp(1≤p≤5 200 0001 \le p \le 5\,200\,000)。

保证所有测试用例中字符串 ww 的总长度不超过 2⋅1052 \cdot 10^5。

输出格式

Output exactly tt rows, the ii-th of them should contain the answer to the ii-th set of input data. Print the longest string that is obtained from ww by deleting letters such that its price is less or equal to pp. 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.

输出恰好 tt 行,其中第 ii 行应包含第 ii 组输入数据的答案。请输出通过对字符串 ww 删除若干字母后所能得到的、价格不超过 pp 的最长字符串。若存在多个满足条件的答案,则输出任意一个即可。

注意:空字符串也是一种可能的答案,此时只需输出一个空字符串。

输入输出样例

  • 输入#1

    5
    abca
    2
    abca
    6
    codeforces
    1
    codeforces
    10
    codeforces
    100

    输出#1

    aa
    abc
    
    cdc
    codeforces

输入解题思路,AI测评打分。不知道怎么写?

首页