luogu#P10074. [GDKOI2024 普及组] 刷野 III

[GDKOI2024 普及组] 刷野 III

Problem Description

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

However, for some mysterious reason, Zayin cannot control which monster he hits. More specifically, there is a permutation pp of length nn. When Zayin attacks the ii-th monster, he is actually attacking the pip_i-th monster.

Each time, Zayin may choose an integer k[1,n]k \in [1, n], causing the HP of the pkp_k-th monster to decrease by 11. When a monster's HP becomes less than or equal to 00, that monster dies.

However, Zayin does not know what the permutation pp is, and he also cannot see the exact remaining HP of each monster. He can only know whether the monster dies after each attack.

Now Zayin wants to know: if he uses the best strategy, in the worst case, how many attacks are needed at most to kill mm monsters.

Input Format

The first line contains two positive integers n,m(1mn2000)n, m(1 \leq m \leq n \leq 2000), where nn is the number of monsters and mm is the number of monsters Zayin needs to kill.

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 HP of the ii-th monster.

Output Format

Output one integer, the minimum number of attacks.

2 1
10 15
15
2 1
10 30
20

Hint

Sample Explanation

In the first sample, Zayin will keep attacking one monster until it dies.

In the second sample, Zayin first attacks one monster 1010 times. If it does not die, then it means he is attacking the monster with 3030 HP. At this point, Zayin will choose to attack the second monster. After attacking it 1010 times, the other monster must die, so in the worst case 2020 attacks are needed.

Constraints

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

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

For another 30%30\% of the testdata, 1mn5001 \leq m \leq n \leq 500.

For 100%100\% of the testdata, 1mn20001 \leq m \leq n \leq 2000, 1ai1091 \leq a_i \leq 10^9.

Translated by ChatGPT 5