#C8691. Remove K Characters for Maximum Lexicographical Order

    ID: 52701 Type: Default 1000ms 256MiB

Remove K Characters for Maximum Lexicographical Order

Remove K Characters for Maximum Lexicographical Order

Given a string ( s ) and an integer ( k ), remove exactly ( k ) characters from ( s ) such that the resulting string is the largest lexicographically possible. The relative order of the remaining characters is preserved. Formally, if ( s = s_1 s_2 \cdots s_n ), remove ( k ) characters to obtain a string ( t ) that is maximum in lexicographical order.

inputFormat

The input consists of two lines:

  1. The first line contains a non-empty string ( s ) consisting of lowercase letters.
  2. The second line contains an integer ( k ) representing the number of characters to remove.

outputFormat

Output a single line containing the lexicographically largest string possible after exactly ( k ) characters have been removed.## sample

abcde
2
cde