#GD0000196. Xâu không rẻ (Not a Cheap String)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xâu không rẻ (Not a Cheap String)
Not a Cheap String
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
The price of a lowercase English string is the sum of the values of its letters: a costs , b costs , and so on through z, which costs . Repeated occurrences contribute their costs separately. For example, abca costs .
You are given a string and a budget . You may delete characters at arbitrary positions, but the relative order of all remaining characters must stay unchanged. The resulting string must have a total price at most .
Keep as many characters as possible and print the resulting string. Any maximum-length valid string is accepted. The result may be empty. If the original string already costs at most , it must be printed unchanged.
Input
- The first line contains a lowercase English string .
- The second line contains an integer , the maximum allowed total price.
Output
Print one line containing a longest subsequence of whose total price does not exceed . Print an empty line if no character can be kept.
Subtasks
- Subtask 1 (20 points): ; ; Every character of is in
a–z. - Subtask 2 (30 points): ; ; Every character of is in
a–z. - Subtask 3 (50 points): ; ; Every character of is in
a–z.
Examples
Input
abca
2
Output
aa
Explanation
The original string abca costs , exceeding . Keeping the first and last a produces aa at price . Keeping three characters is impossible because even the three cheapest occurrences cost . Thus the maximum length is .