[Solution] Not a Cheap String Codeforces Solution
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.
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.
Round Down the Price Codeforces Solution
Polycarp Writes a String from Memory Codeforces Solution
Train and Queries Codeforces Solution
Not a Cheap String Codeforces Solution
Split Into Two Sets Codeforces Solution
Equate Multisets Codeforces Solution
Passable Paths (easy version) Codeforces Solution
Passable Paths (hard version) Codeforces Solution
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 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.
No comments:
Post a Comment