#C9729. Lexicographically Largest String after Removal
Lexicographically Largest String after Removal
Lexicographically Largest String after Removal
Given a string \(S\) and an integer \(K\), remove exactly \(K\) characters from \(S\) so that the resulting string is lexicographically largest. The lexicographical order is defined as the dictionary order, where given two strings, the first differing character determines which string is larger.
Formally, let \(S\) be a string of length \(n\) and \(K\) an integer satisfying \(0 \le K \le n\). You need to select a subset of characters (preserving their original order) from \(S\) by removing exactly \(K\) characters, such that the remaining string \(T\) is the largest possible in lexicographical order among all possibilities.
For example, if \(S = \texttt{abcde}\) and \(K = 2\), one valid removal is to remove the first two characters, resulting in \(\texttt{cde}\), which is the lexicographically largest outcome.
inputFormat
The input is provided on a single line via standard input. It contains a string \(S\) (consisting of lowercase English letters) and an integer \(K\), separated by a space.
outputFormat
Output the lexicographically largest string that can be obtained after removing exactly \(K\) characters from \(S\) via standard output.
## sampleabcde 2
cde
</p>