atcoder#ABC288B. [ABC288B] Qualification Contest
[ABC288B] Qualification Contest
Score : points
Problem Statement
There were participants in a contest. The participant ranked -th had the nickname . Print the nicknames of the top participants in lexicographical order.
What is lexicographical order?
Simply put, the lexicographical order is the order of words in a dictionary. As a formal description, below is an algorithm to order distinct strings and .
Let denote the -th character of a string . We write if is lexicographically smaller than , and if is larger.
- Let be the length of the shorter of and . For , check whether equals .
- If there is an such that , let be the smallest such . Compare and . If is alphabetically smaller than , we get ; if is larger, we get .
- If there is no such that , compare the lengths of and . If is shorter than , we get ; if is longer, we get .
Constraints
- and are integers.
- is a string of length consisting of lowercase English letters.
- if .
Input
The input is given from Standard Input in the following format:
Output
Print the nicknames, separated by newlines.
5 3
abc
aaaaa
xyz
a
def
aaaaa
abc
xyz
This contest had five participants. The participants ranked first, second, third, fourth, and fifth had the nicknames abc
, aaaaa
, xyz
, a
, and def
, respectively.
The nicknames of the top three participants were abc
, aaaaa
, xyz
, so print these in lexicographical order: aaaaa
, abc
, xyz
.
4 4
z
zyx
zzz
rbg
rbg
z
zyx
zzz
3 1
abc
arc
agc
abc