#P10072. [GDKOI2024 普及组] 刷野 I

[GDKOI2024 普及组] 刷野 I

Problem Description

Zayin is a wizard who fights monsters. This time, he will face nn monsters standing in a line, where the ii-th monster has health aia_i.

Zayin attacks first using one type of attack. After the attack, all monsters with health less than or equal to 00 die. After each time Zayin attacks, all surviving monsters deal 11 point of damage to Zayin. The above process repeats until Zayin kills all monsters.

Zayin has three types of attacks:

  • Normal Attack: Costs 00 energy. Choose one monster and reduce its health by 11.

  • "Tianyinbo": Costs 11 energy. Choose one monster and reduce its health by 22.

  • "Tianleipo": Costs 11 energy. Reduce the health of all monsters by 11.

Now Zayin has mm energy in total. He wants to know, under the optimal strategy, the minimum amount of health he will lose to defeat the nn monsters.

Input Format

The first line contains two positive integers n,m(1n,m105)n, m(1 \leq n, m \leq 10^5), where nn is the number of monsters and mm is the amount of energy Zayin has.

The second line contains nn non-negative integers a1,a2,,an(1ai109)a_1, a_2, \dots, a_n(1 \leq a_i \leq 10^9), where aia_i is the health of the ii-th monster.

Output Format

Output one integer in one line, representing the answer.

3 4
2 4 4
6

Hint

For 30%30\% of the testdata, 1n,m51 \leq n, m \leq 5.

For another 15%15\% of the testdata, m=0m = 0.

For another 15%15\% of the testdata, all aia_i are equal.

For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 0m1050 \leq m \leq 10^5, 1ai1091 \leq a_i \leq 10^9.

Translated by ChatGPT 5