Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 500 点
問題文
カードが N 枚あり、i 番目のカードには文字列 S_i が書かれています。
この中からちょうど K 枚選び、好きな順序で繋げてできる文字列のうち辞書順最小のものを求めてください。
制約
- 1 \leq K \leq N \leq 50
- 1 \leq |S_i| \leq 50
- S_i は英小文字からなる
入力
入力は以下の形式で標準入力から与えられる。
N K S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
4 3 ode zaaa r atc
出力例 1
atcoder
カードの中に書かれている文字を、反転させたり並び替えたりすることはできません。
たとえば 1 枚目のカードに書かれている ode
を、edo
や deo
のように使うことはできません。
入力例 2
5 2 z z zzz z zzzzzz
出力例 2
zz
S_i = S_j を満たす i,j(i\neq j) の組が存在することもあります。
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.