#C14185. Lexicographically Smallest String After Fixed Deletions

    ID: 43806 Type: Default 1000ms 256MiB

Lexicographically Smallest String After Fixed Deletions

Lexicographically Smallest String After Fixed Deletions

You are given a string \(s\) consisting of lowercase English letters and an integer \(k\). Your task is to remove exactly \(k\) characters from \(s\) and then reorganize the remaining characters into non-decreasing order (i.e. sorted order) so that the resulting string is lexicographically as small as possible.

Note: The reorganization means that you can rearrange the remaining letters arbitrarily, but the final answer must be sorted in ascending order.

Input Constraints:

  • \(1 \leq |s| \leq 10^5\)
  • \(0 \leq k \leq |s|\)

Example:

  • For \(s = \texttt{bcabc}\) and \(k = 2\), one valid answer is abc.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains the string \(s\) of lowercase English letters.
  2. The second line contains the integer \(k\), the exact number of characters to remove from \(s\).

outputFormat

Output the lexicographically smallest string (in non-decreasing order) that can be obtained by removing exactly \(k\) characters from \(s\), printing the answer to standard output (stdout). If all characters are removed, output an empty string.

## sample
bcabc
2
abc