#4534. Qualification Contest

0

Qualification Contest

Qualification Contest

题目描述

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.

什么是字典顺序?

简单来说,字典顺序就是词典中的单词排列顺序。作为形式化描述,下面给出对不同字符串 SS 和 TT 的排序算法。

令 SiS_i 表示字符串 SS 的第 ii 个字符。我们写 S<TS \lt T 若 SS 在字典序上小于 TT,写 S>TS \gt T 若 SS 在字典序上大于 TT。

    令 $L$ 为 $S$ 和 $T$ 中较短者的长度。对于 $i=1,2,\dots,L$,检查 $S_i$ 是否等于 $T_i$。 如果存在某个 $i$ 使得 $S_i \neq T_i$,令 $j$ 为最小的这样的 $i$。比较 $S_j$ 与 $T_j$。若 $S_j$ 在字母表中比 $T_j$ 更靠前,则 $S \lt T$;若 $S_j$ 更靠后,则 $S \gt T$。 如果不存在这样的 $i$,比较 $S$ 和 $T$ 的长度。若 $S$ 比 $T$ 短,$S \lt T$;若 $S$ 比 $T$ 长,$S \gt T$。

输入格式

The input is given from Standard Input in the following format: NN KK S1S_1 S2S_2 ⋮\vdots SNS_N

输出格式

Print the nicknames, separated by newlines.

5 3
abc
aaaaa
xyz
a
def
aaaaa
abc
xyz
4 4
z
zyx
zzz
rbg
rbg
z
zyx
zzz
3 1
abc
arc
agc
abc

提示

1≤K≤N≤1001 \leq K \leq N \leq 100 KK and NN are integers. SiS_i is a string of length 1010 consisting of lowercase English letters. Si≠SjS_i \neq S_j if i≠ji \neq j.This contest had five participants. The participants ranked first, second, third, fourth, and fifth had the nicknames abcabc, aaaaaaaaaa, xyzxyz, aa, and defdef, respectively. The nicknames of the top three participants were abcabc, aaaaaaaaaa, xyzxyz, so print these in lexicographical order: aaaaaaaaaa, abcabc, xyzxyz.

标签: AtCoder|abc288B

来源

AtCoder|abc288B