#P12085. [蓝桥杯 2023 省 B] 整数删除
[蓝桥杯 2023 省 B] 整数删除
Problem Description
Given an integer sequence of length : . You need to repeat the following operation 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 operations.
Input Format
The first line contains two integers and .
The second line contains integers: .
Output Format
Output integers, separated by a single space, representing the sequence after 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 of the testdata, .
For of the testdata, , and .
Lanqiao Cup 2023 NOI Qualifier B Group, Problem H.
Translated by ChatGPT 5