#abc225f. F - String Cards

F - String Cards

Score : 500500 points

问题描述

我们有 NN 张卡片。第 ii 张卡片上写有一个字符串 SiS_i

找出通过任意顺序选取其中 KK 张卡片并将它们连接起来能得到的字典序最小的字符串。

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

Problem Statement

We have NN cards. The ii-th card has a string SiS_i written on it.

Find the lexicographically smallest string that can be obtained by choosing KK of these cards and concatenating them in any order.

Constraints

  • 1KN501 \leq K \leq N \leq 50
  • 1Si501 \leq |S_i| \leq 50
  • SiS_i consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

NN KK

S1S_1

S2S_2

\vdots

SNS_N

Output

Print the answer.

Sample Input 1

4 3
ode
zaaa
r
atc

Sample Output 1

atcoder

Note that it is not possible to reverse or permute the string written on a card.
For example, ode written on the first card cannot be used as edo or deo.

Sample Input 2

5 2
z
z
zzz
z
zzzzzz

Sample Output 2

zz

There may be a pair i,ji, j (ij)(i\neq j) such that Si=SjS_i = S_j.

update @ 2024/3/10 09:53:45