P10904 [Lanqiao Cup 2024 NOI Qualifier C] Mining.

Description

Xiao Lan is mining on a number line. There are $n$ mines on the number line, and the coordinate of the $i$-th mine is $a_i$. Xiao Lan starts from $0$. Each time, he can move $1$ unit to the left or right. When he passes a mine, he will mine it and gain $1$ 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 $m$, what is the maximum number of ore units he can obtain?

Input Format

The first line contains two positive integers $n, m$, separated by a space. The second line contains $n$ integers $a_1, a_2, \cdots, a_n$, with a space between adjacent integers.

Output Format

Output one line containing one integer, which is the answer.

Explanation/Hint

**[Sample Explanation]** Path: $0 \to -1 \to 0 \to 1 \to 2$, you can mine the four mines $\{0, -1, 1, 2\}$ and obtain at most $4$ ore pieces. **[Scale and Constraints of Test Cases]** For $20\%$ of the test cases, $1 \le n \le 10^3$. For all test cases, $1 \le n \le 10^5$, $-10^6 \le a_i \le 10^6$, $1 \le m \le 2 \times 10^6$. Translated by ChatGPT 5