#P10904. [蓝桥杯 2024 省 C] 挖矿
[蓝桥杯 2024 省 C] 挖矿
Problem Description
Xiao Lan is mining on a number line. There are mines on the number line, and the coordinate of the -th mine is . Xiao Lan starts from . Each time, he can move unit to the left or right. When he passes a mine, he will mine it and gain unit of ore, but a mine cannot be mined more than once. Xiao Lan wants to know: under the condition that the total moving distance does not exceed , what is the maximum number of ore units he can obtain?
Input Format
The first line contains two positive integers , separated by a space.
The second line contains integers , with a space between adjacent integers.
Output Format
Output one line containing one integer, which is the answer.
5 4
0 -3 -1 1 2
4
Hint
[Sample Explanation]
Path: , you can mine the four mines and obtain at most ore pieces.
[Scale and Constraints of Test Cases]
For of the test cases, .
For all test cases, , , .
Translated by ChatGPT 5