#K60507. Largest Lexicographical String After Removal
Largest Lexicographical String After Removal
Largest Lexicographical String After Removal
You are given a string \(S\) and an integer \(k\). Your task is to remove exactly \(k\) characters from \(S\) so that the resulting string is the maximum possible lexicographical order. In other words, you need to choose a subsequence of \(S\) (by removing exactly \(k\) characters, preserving order) that is lexicographically the largest.
Note: It is guaranteed that \(0 \leq k < |S|\) for each test case.
Example: For \(S = \texttt{abcdefg}\) and \(k = 2\), one optimal answer is \(\texttt{cdefg}\), which is the largest string obtainable under the conditions.
inputFormat
The first line contains an integer \(T\) denoting the number of test cases. Each of the following \(T\) lines contains a test case, where each test case consists of a string \(S\) and an integer \(k\) separated by a space.
You can assume that:
- \(1 \leq T \leq 10^4\)
- \(S\) consists only of lowercase English letters.
- \(0 \leq k < |S|\)
outputFormat
For each test case, output the largest lexicographical string you can get by removing exactly \(k\) characters from \(S\). Each answer should be on a new line.
## sample1
abcdefg 2
cdefg
</p>