309581: CF1702D. Not a Cheap String

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Not a Cheap String

题意翻译

设 $s$ 为一个由小写拉丁字母组成的字符串。它的价格被定义为,字符串中每个字母在字母表中的位置的和。 比如,字符串 $\texttt{abca}$ 的价格是 $1 + 2 + 3 + 1 = 7$。 现在给你一个字符串 $w (|w| \le 2\cdot 10^5)$,和一个整数 $p$,请你从字符串中**尽量少**的移除字母,使得 $w$ 的价格小于或等于 $p (1 \le p \le 5\ 200\ 000)$。注意移除的字母数量可以是 $0$ 个,也可以是字符串中全部的字母。 答案不唯一,输出任意一种即可。 注意:一个测试点包含多组测试数据,第一行输入一个整数 $t\ (1\le t\le 10^4)$ 表示数据组数。保证 $\sum |w|\le 2\times 10^5$。 由 [tzyt](https://www.luogu.com.cn/user/394488) 翻译

题目描述

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

输出格式


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.

输入输出样例

输入样例 #1

5
abca
2
abca
6
codeforces
1
codeforces
10
codeforces
100

输出样例 #1

aa
abc

cdc
codeforces

Input

题意翻译

设 $s$ 为一个由小写拉丁字母组成的字符串。它的价格被定义为,字符串中每个字母在字母表中的位置的和。 比如,字符串 $\texttt{abca}$ 的价格是 $1 + 2 + 3 + 1 = 7$。 现在给你一个字符串 $w (|w| \le 2\cdot 10^5)$,和一个整数 $p$,请你从字符串中**尽量少**的移除字母,使得 $w$ 的价格小于或等于 $p (1 \le p \le 5\ 200\ 000)$。注意移除的字母数量可以是 $0$ 个,也可以是字符串中全部的字母。 答案不唯一,输出任意一种即可。 注意:一个测试点包含多组测试数据,第一行输入一个整数 $t\ (1\le t\le 10^4)$ 表示数据组数。保证 $\sum |w|\le 2\times 10^5$。 由 [tzyt](https://www.luogu.com.cn/user/394488) 翻译

Output

题目大意:
给定一个由小写拉丁字母组成的字符串s,其价格定义为字符串中每个字母在字母表中位置的之和。例如,字符串abca的价格为1+2+3+1=7。现在给你一个字符串w和一个整数p,请从字符串中尽量少地移除字母,使得w的价格小于或等于p。注意移除的字母数量可以是0个,也可以是字符串中全部的字母。答案不唯一,输出任意一种即可。

输入输出数据格式:
输入格式:
第一行输入一个整数t(1≤t≤10^4),表示数据组数。接下来t组数据,每组数据有两行,第一行是一个由小写拉丁字母组成的字符串w(|w|≤2×10^5),第二行是一个整数p(1≤p≤5 200 000)。保证所有测试数据的字符串长度之和不超过2×10^5。

输出格式:
输出t行,每行对应一个测试数据的答案。输出从w中删除字母后得到的字符串,使得其价格小于或等于p。如果存在多个答案,输出任意一个即可。如果答案为空字符串,直接输出空字符串即可。题目大意: 给定一个由小写拉丁字母组成的字符串s,其价格定义为字符串中每个字母在字母表中位置的之和。例如,字符串abca的价格为1+2+3+1=7。现在给你一个字符串w和一个整数p,请从字符串中尽量少地移除字母,使得w的价格小于或等于p。注意移除的字母数量可以是0个,也可以是字符串中全部的字母。答案不唯一,输出任意一种即可。 输入输出数据格式: 输入格式: 第一行输入一个整数t(1≤t≤10^4),表示数据组数。接下来t组数据,每组数据有两行,第一行是一个由小写拉丁字母组成的字符串w(|w|≤2×10^5),第二行是一个整数p(1≤p≤5 200 000)。保证所有测试数据的字符串长度之和不超过2×10^5。 输出格式: 输出t行,每行对应一个测试数据的答案。输出从w中删除字母后得到的字符串,使得其价格小于或等于p。如果存在多个答案,输出任意一个即可。如果答案为空字符串,直接输出空字符串即可。

加入题单

算法标签: