#C1557. Longest Special String
Longest Special String
Longest Special String
Given a list of strings and an integer \(X\), your task is to find the longest string in the list that contains exactly \(X\) unique characters. In case there are multiple strings with the same maximum length, choose the one that comes first in lexicographical order. If no such string exists, output an empty string.
You must read the input from standard input (stdin) and write the result to standard output (stdout).
inputFormat
The input is given in the following format:
- The first line contains an integer \(n\) denoting the number of strings.
- The next \(n\) lines each contain a string.
- The last line contains an integer \(X\) which is the required number of unique characters in the string.
outputFormat
Output the longest string that has exactly \(X\) unique characters. If there are multiple candidates with the same length, output the one that is lexicographically smallest. If no such string exists, output an empty string.
## sample5
hello
abc
defg
abcdefgh
xyz
3
abc