#P12085. [蓝桥杯 2023 省 B] 整数删除

[蓝桥杯 2023 省 B] 整数删除

Problem Description

Given an integer sequence of length NN: A1,A2,,ANA_{1}, A_{2}, \ldots, A_{N}. You need to repeat the following operation KK times:

Each time, choose the smallest integer in the sequence (if the minimum value appears more than once, choose the leftmost one), delete it, and add its value to the integers adjacent to it.

Output the sequence after KK operations.

Input Format

The first line contains two integers NN and KK.

The second line contains NN integers: A1,A2,A3,,ANA_{1}, A_{2}, A_{3}, \ldots, A_{N}.

Output Format

Output NKN - K integers, separated by a single space, representing the sequence after KK operations.

5 3
1 4 2 8 7
17 7

Hint

Sample Explanation

The sequence changes as follows. The number in brackets is the number chosen in that operation:

[1] 4 2 8 7
5 [2] 8 7
[7] 10 7
17 7

Constraints

For 20%20\% of the testdata, 1K<N1041 \leq K < N \leq 10^4.

For 100%100\% of the testdata, 1K<N5×1051 \leq K < N \leq 5 \times 10^{5}, and 0Ai1080 \leq A_{i} \leq 10^{8}.

Lanqiao Cup 2023 NOI Qualifier B Group, Problem H.

Translated by ChatGPT 5