#abc288b. B - Qualification Contest

B - Qualification Contest

Score : 200200 points

问题描述

在一次竞赛中有 NN 名参与者。排名第 ii 位的参赛者昵称为 SiS_i
请按 字典序顺序 打印前 KK 名参赛者的昵称。

什么是字典序顺序?

简而言之,字典序顺序就是词典中单词排列的顺序。作为正式描述,以下是一种对不重复字符串 SSTT 进行排序的算法。

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

  1. 计算 SSTT 中较短者的长度,记为 LL。对于 i=1,2,,Li=1,2,\dots,L,检查 SiS_i 是否等于 TiT_i
  2. 若存在某个 ii 使得 SiTiS_i \neq T_i,取最小这样的 ii 值,记为 jj。比较 SjS_jTjT_j。若 SjS_j 字母表顺序上小于 TjT_j,则有 S<TS \lt T;若 SjS_j 更大,则有 S>TS \gt T
  3. 若不存在使 SiTiS_i \neq T_iii,则比较 SSTT 的长度。若 SSTT 短,则有 S<TS \lt T;若 SS 更长,则有 S>TS \gt T

综上所述,请按照上述字典序顺序规则,输出前 KK 名参赛者的昵称。

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

5 3
abc
aaaaa
xyz
a
def

Sample Output 1

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 Input 2

4 4
z
zyx
zzz
rbg

Sample Output 2

rbg
z
zyx
zzz

Sample Input 3

3 1
abc
arc
agc

Sample Output 3

abc

update @ 2024/3/10 12:01:36