102255: [AtCoder]ABC225 F - String Cards
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Score : $500$ points
Problem Statement
We have $N$ cards. The $i$-th card has a string $S_i$ written on it.
Find the lexicographically smallest string that can be obtained by choosing $K$ of these cards and concatenating them in any order.
Constraints
- $1 \leq K \leq N \leq 50$
- $1 \leq |S_i| \leq 50$
- $S_i$ consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
$N$ $K$ $S_1$ $S_2$ $\vdots$ $S_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, j$ $(i\neq j)$ such that $S_i = S_j$.
Input
题意翻译
给出 $N$ 个串,请你在其中选出 $K$ 个串,使得这 $K$ 个串前后拼接形成的串字典序最小。Output
得分:500分
问题描述
我们有N张卡片。第i张卡片上写着一个字符串Si。
找出可以通过选择其中的K张卡片并按任意顺序连接它们得到的字典序最小的字符串。
限制条件
- 1≤K≤N≤50
- 1≤|Si|≤50
- Si由小写英文字母组成。
输入
输入格式如下:
N K S1 S2 vdots SN
输出
输出答案。
样例输入1
4 3 ode zaaa r atc
样例输出1
atcoder
请注意,无法反转或排列卡片上写的字符串。
例如,第一张卡片上写的ode
不能用作edo
或deo
。
样例输入2
5 2 z z zzz z zzzzzz
样例输出2
zz
可能存在一对i, j (i≠j)使得Si=Sj。