atcoder#ABC288B. [ABC288B] Qualification Contest

[ABC288B] Qualification Contest

Score : 200200 points

Problem Statement

There were NN participants in a contest. The participant ranked ii-th had the nickname SiS_i. Print the nicknames of the top KK 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 SS and TT.

Let SiS_i denote the ii-th character of a string SS. We write S<TS \lt T if SS is lexicographically smaller than TT, and S>TS \gt T if SS is larger.

  1. Let LL be the length of the shorter of SS and TT. For i=1,2,,Li=1,2,\dots,L, check whether SiS_i equals TiT_i.
  2. If there is an ii such that SiTiS_i \neq T_i, let jj be the smallest such ii. Compare SjS_j and TjT_j. If SjS_j is alphabetically smaller than TjT_j, we get S<TS \lt T; if SjS_j is larger, we get S>TS \gt T.
  3. If there is no ii such that SiTiS_i \neq T_i, compare the lengths of SS and TT. If SS is shorter than TT, we get S<TS \lt T; if SS is longer, we get S>TS \gt T.

Constraints

  • 1KN1001 \leq K \leq N \leq 100
  • KK and NN are integers.
  • SiS_i is a string of length 1010 consisting of lowercase English letters.
  • SiSjS_i \neq S_j if iji \neq j.

Input

The input is given from Standard Input in the following format:

NN KK

S1S_1

S2S_2

\vdots

SNS_N

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