Problems > Largest Concatenation

Largest Concatenation

Difficulty: 1600 3000 ms 128 MB

greedy sorting

Arrange the numbers in some order and concatenate their decimal representations. Print the largest number you can form (as a string, no leading zeros unless the value is 0).

Input: the first line has N; the second line has N non-negative integers.

Output: the largest concatenation.

Constraints:

  • 1 ≤ N ≤ 104
  • 0 ≤ ai ≤ 1000

Sample Tests

Input 1
3
10 2 9
Output 1
9210
Input 2
2
0 0
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.