Ciąg
Time limit1sMemory limit128 MB
Bajtek needs the shortest string over the given alphabet that is not a subsequence of the word, and the lexicographically smallest among shortest such strings.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, String, Prefix sum
- Solved
- No attempts yet
Problem
Bajtek got bored with Bajcraft and went looking for a new pastime. While browsing Bajternet he found a contest that pays out a lot of Bajtalars. In each round the organizers fix an alphabet and a word, and you win by submitting a string of minimal length, built from that alphabet, that is not a subsequence of the word. A subsequence of a word is any word obtained by deleting zero or more of its letters, keeping the remaining letters in their original order. Whoever submits such a shortest string first wins, and the prize is doubled for the string that is also the smallest in lexicographic (dictionary) order.
The rounds keep growing, so Bajtek asked you for a program. Given the alphabet and the word, find the shortest string over the alphabet that is not a subsequence of the word. If more than one shortest string exists, output the lexicographically smallest one.
Input
The first line contains two integers and (, ): the alphabet size and the length of the word. An alphabet of size consists of the first lowercase letters of the English alphabet (for example, gives the letters a, b, and c). The second line contains the word of length , made up only of letters from this alphabet.
Output
Print a single line with the required string, its letters written with no spaces between them.