#C1375. Remove K Digits
Remove K Digits
Remove K Digits
Given a non-negative integer represented as a string s and an integer k, remove exactly k digits from s so that the resulting number is the smallest possible. The order of the remaining digits must be preserved.
For example, when s = "1432219" and k = 3, the smallest possible number after removing 3 digits is "1219". Note that the resulting number should not contain any leading zeros unless the number is exactly zero.
The problem can be mathematically formulated as follows: Given a string \( s \) of digits and an integer \( k \), find a subsequence of \( s \) of length \( n-k \) that represents the smallest possible integer. Use the property of greedy selection where for each digit you decide whether to remove a previous digit if it is larger than the current one.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains the string s representing the non-negative integer.
- The second line contains the integer k, which represents the number of digits to remove.
outputFormat
Output the smallest possible integer (as a string) after removing exactly k digits from s. The output is written to standard output (stdout).
## sample1432219
3
1219