#P10904. [蓝桥杯 2024 省 C] 挖矿

[蓝桥杯 2024 省 C] 挖矿

Problem Description

Xiao Lan is mining on a number line. There are nn mines on the number line, and the coordinate of the ii-th mine is aia_i. Xiao Lan starts from 00. Each time, he can move 11 unit to the left or right. When he passes a mine, he will mine it and gain 11 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 mm, what is the maximum number of ore units he can obtain?

Input Format

The first line contains two positive integers n,mn, m, separated by a space.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n, 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: 010120 \to -1 \to 0 \to 1 \to 2, you can mine the four mines {0,1,1,2}\{0, -1, 1, 2\} and obtain at most 44 ore pieces.

[Scale and Constraints of Test Cases]

For 20%20\% of the test cases, 1n1031 \le n \le 10^3.

For all test cases, 1n1051 \le n \le 10^5, 106ai106-10^6 \le a_i \le 10^6, 1m2×1061 \le m \le 2 \times 10^6.

Translated by ChatGPT 5