#C11471. Smallest Number by Removing Digits

    ID: 40791 Type: Default 1000ms 256MiB

Smallest Number by Removing Digits

Smallest Number by Removing Digits

Given a non-negative integer represented as a string num and an integer k, remove exactly k digits from num so that the resulting number is the smallest possible. Note that the result should not contain any leading zeros (except for the number zero itself). The problem can be mathematically represented by finding a subsequence of digits satisfying the following constraint: [ \min_{\substack{S \subseteq {0,1,\dots,n-1} \ |S| = n-k}} \text{num}_S ] where (\text{num}_S) represents the number formed by the digits at indices in S with their original order. This is a typical greedy and stack based problem.

inputFormat

The input consists of two lines. The first line contains a non-negative integer represented as a string num. The second line contains a single integer k representing the number of digits to remove.

outputFormat

Output the smallest number possible (as a string) after removing exactly k digits. The output should not contain any leading zeros except when the result is exactly zero.## sample

1432219
3
1219