Problem9207--ABC288 —— B - Qualification Contest

9207: ABC288 —— B - Qualification Contest

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

There were $N$ participants in a contest. The participant ranked $i$-th had the nickname $S_i$.  
Print the nicknames of the top $K$ 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 $S$ and $T$.

Let $S_i$ denote the $i$\-th character of a string $S$. We write $S \lt T$ if $S$ is lexicographically smaller than $T$, and $S \gt T$ if $S$ is larger.

1.  Let $L$ be the length of the shorter of $S$ and $T$. For $i=1,2,\dots,L$, check whether $S_i$ equals $T_i$.
2.  If there is an $i$ such that $S_i \neq T_i$, let $j$ be the smallest such $i$. Compare $S_j$ and $T_j$. If $S_j$ is alphabetically smaller than $T_j$, we get $S \lt T$; if $S_j$ is larger, we get $S \gt T$.
3.  If there is no $i$ such that $S_i \neq T_i$, compare the lengths of $S$ and $T$. If $S$ is shorter than $T$, we get $S \lt T$; if $S$ is longer, we get $S \gt T$.

Input

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

```
$N$ $K$
$S_1$
$S_2$
$\vdots$
$S_N$
```

Output

Print the nicknames, separated by newlines.

Constraints

-   $1 \leq K \leq N \leq 100$
-   $K$ and $N$ are integers.
-   $S_i$ is a string of length $10$ consisting of lowercase English letters.
-   $S_i \neq S_j$ if $i \neq j$.

Sample 1 Input

5 3
abc
aaaaa
xyz
a
def

Sample 1 Output

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.

Sample 2 Input

4 4
z
zyx
zzz
rbg

Sample 2 Output

rbg
z
zyx
zzz

Sample 3 Input

3 1
abc
arc
agc

Sample 3 Output

abc

Source/Category