#K61507. Smallest Lexicographical String after Removal
Smallest Lexicographical String after Removal
Smallest Lexicographical String after Removal
In this problem, you are given a string ( s ) and an integer ( k ). Your task is to remove exactly ( k ) characters from ( s ) such that the resulting string is the lexicographically smallest possible. This problem requires a greedy approach where you can use a stack (or similar data structure) to decide which characters to remove.
For example, if ( s = \texttt{abcde} ) and ( k = 2 ), the answer will be ( \texttt{abc} ) because removing characters appropriately yields the smallest possible string in lexicographical order.
inputFormat
The input is read from standard input (stdin). It consists of two lines:
- The first line contains the string ( s ).
- The second line contains the integer ( k ), representing the number of characters to remove.
outputFormat
Output the lexicographically smallest string possible after removing exactly ( k ) characters. The result should be printed to standard output (stdout).## sample
abcde
2
abc