#P12085. Sequence Operations

    ID: 14191 Type: Default 1000ms 256MiB

Sequence Operations

Sequence Operations

Given an integer sequence \(A_1, A_2, \ldots, A_N\). You are to perform the following operation K times:

In each operation, select the smallest integer in the sequence (if there are multiple, choose the one with the smallest index), remove it, and add its value to its adjacent neighbor(s). Note that if the removed element is at one end of the sequence, it only has one adjacent neighbor. After performing \(K\) operations, output the final sequence.

inputFormat

The first line contains two integers \(N\) and \(K\) (the length of the sequence and the number of operations, respectively). The second line contains \(N\) space-separated integers representing \(A_1, A_2, \ldots, A_N\).

outputFormat

Output the final sequence after performing \(K\) operations. The numbers should be printed in one line separated by a space.

sample

5 2
3 1 5 2 4
4 8 6