#ABC471F. 拼接(最大化) / Concat (maximize)

拼接(最大化) / Concat (maximize)

题目描述

You are given NN strings S1,,SNS_1,\ldots,S_N consisting of digits.

Find the maximum possible value, when interpreted as a decimal integer (after removing extra leading zeros), of a string obtained by choosing exactly KK of these strings and concatenating them in any order of your choice.

Here, the value obtained by interpreting a string consisting entirely of the character 0 as a decimal integer after removing extra leading zeros is defined to be 00.

输入格式

The input is given from Standard Input in the following format:

  • NN KK
  • S1S_1
  • \vdots
  • SNS_N

输出格式

Output the answer.

数据范围

  • 1KN1051 \leq K \leq N \leq 10^5
  • SiS_i is a string of length between 11 and 1010 (inclusive) consisting of digits.
  • NN and KK are integers.
3 2
123
45
6
45123

There are six strings obtained by choosing two of 123, 45, 6 and concatenating them: 12345, 1236, 45123, 456, 6123, 645.

Among these, the maximum value when interpreted as a decimal integer is 4512345123.

5 3
00000
00
1
0000
000
1000000000
9 9
0000000001
000000002
00000003
0000004
000005
00006
0007
008
09
90080007000060000050000004000000030000000020000000001

The answer must be output without extra leading zeros.