print1594. Big number

printBig number

Ограничения: время – 1s/2s, память – 64MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

Trillion, quadrillion, quintillion, sextillion, septillion, octillion — all is trifle! Vasya knows how to get a really big number. One should consider several “ordinary” numbers, and then write them down consequently one after another on a piece of paper.
Vasya decided to demonstrate this idea to his elder brother Pete. He prepared a sequence of N positive integers and started writing them down one after another on a piece of paper.
After observing this process for a while, Pete got tired and suggested Vasya to solve the following puzzle. Vasya’s goal is to remove exactly `K` numbers from his sequence so that if one concatenates the remaining numbers (keeping the original order) he gets the largest possible number.
Please, help Vasya.
Input
The first line contains two integers `N` and `K` denoting how many numbers are prepared by Vasya and how many of them should be removed, respectively (`2\ ≤\ N\ ≤\ 100000`, `1\ ≤\ K\ ≤N-1` and `K\ ≤\ 100`). The second line contains `N` space separated positive integers not exceeding 1000000000.
Output
Please, output the largest possible number Vasya can obtain by removing exactly `K` numbers from the sequence.

Sample Input 1

5 2
123 37 45 9 18

Sample Output 1

1234518

Sample Input 2

7 5
10 567 1 9 654 7 99

Sample Output 2

567654
Source: NEERC Moscow Subregional Contest, 2010

loading