#C4966. Lexicographically Smallest Subsequence
Lexicographically Smallest Subsequence
Lexicographically Smallest Subsequence
Given a string \( S \) and an integer \( N \), your task is to find the lexicographically smallest subsequence of \( S \) with length \( N \). A subsequence is a sequence that can be derived from the string by deleting some or no elements without changing the order of the remaining characters.
For example, for \( S = "abcdef" \) and \( N = 3 \), the answer is "abc". Similarly, for \( S = "zyxabc" \) and \( N = 4 \), the answer is "xabc".
Note: The lexicographical order is defined based on the standard ordering of characters.
Input is taken from standard input (stdin) and output is printed to standard output (stdout).
inputFormat
The input consists of two lines:
- The first line contains a non-empty string \( S \) consisting of lowercase letters.
- The second line contains an integer \( N \) (where \( 1 \leq N \leq |S| \)), which is the desired length of the subsequence.
outputFormat
Output the lexicographically smallest subsequence of \( S \) of length \( N \) to stdout.
## sampleabcdef
3
abc