#P12030. [USACO25OPEN] OohMoo Milk G
[USACO25OPEN] OohMoo Milk G
Description
Farmer John is trying to make his world's famous OohMoo Milk to sell for a profit. He has bottles that he is trying to fill. Each bottle initially contains some amount of milk . Every day, he takes bottles and fills each bottle with one unit of milk.
Unfortunately, Farmer Nhoj, Farmer John's competitor in the business of OohMoo Milk, knows about Farmer John's production processes and has a plan to curtail his business. Every day, after Farmer John fills his bottles, Farmer Nhoj will sneakily steal one unit of milk from each of different nonempty bottles. To remain sneaky, Farmer Nhoj chooses so that it is strictly less than , so that it is less likely for Farmer John to discover him.
After () days, Farmer John will sell his OohMoo Milk. If a bottle has units of milk, it will sell for moonies.
Let be the unique profit such that FJ can guarantee that he makes at least profit regardless of how FN behaves, and FN can guarantee that FJ makes at most profit regardless of how FJ behaves. Output the value of modulo .
Input Format
The first line of the input contains and , where is the number of bottles and is the number of days that take place.
The second line of the input contains and representing the number of units of milk that Farmer John fills and Farmer Nhoj steals respectively.
The third line of the input contains space-separated integers representing the initial amount of milk in each bottle.
Output Format
Output the value of modulo .
5 4
4 2
4 10 8 10 10
546
10 5
5 1
1 2 3 4 5 6 7 8 9 10
777
5 1000000000
3 1
0 1 2 3 4
10
Hint
For Sample 1:
On the first day, Farmer John could add milk to the second, third, fourth, and fifth bottles. Then, Farmer Nhoj could remove milk from the second and fourth bottles.
Thus, the new amount of milk in each bottle is
$$[4, 10, 8, 10, 10] \to [4, 11, 9, 11, 11] \to [4, 10, 9, 10, 11].$$After four days, the amount of milk in each bottle could be
$$[4, 10, 8, 10, 10] \to [4, 10, 9, 10, 11] \to [4, 10, 10, 11, 11] \to [4, 11, 11, 11, 11] \to [4, 11, 11, 12, 12].$$The total amount of moonies Farmer John would make in this situation is . It can be shown that this is the value of .
For Sample 2:
Make sure you output modulo .
SCORING:
- Inputs 4-6: .
- Inputs 7-10: .
- Inputs 11-20: No additional constraints.
京公网安备 11011102002149号