Drought
Time limit1sMemory limit1024 MB
Count N-tuples of hunger levels within given upper bounds for which adjacent-pair feedings can make all cows equal, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Greedy
- Solved
- No attempts yet
Problem
The grass in Farmer John's pasture has dried up because of a drought. After hours of despair and contemplation, FJ comes up with the idea of buying corn to feed his precious cows.
FJ's cows () stand in a line, and the -th cow in line has a non-negative integer hunger level . Because FJ's cows are social animals and insist on eating together, the only way FJ can decrease their hunger levels is to pick two adjacent cows and and feed each of them a bag of corn, which decreases each of their hunger levels by one.
FJ wants to feed his cows until all of them have the same non-negative hunger level. He does not know his cows' exact hunger levels, but he does know an upper bound on each cow's hunger level: the hunger level of the -th cow is at most ().
Among the -tuples of hunger levels that are consistent with these upper bounds, count those for which FJ can achieve his goal, modulo .
Input
The first line contains .
The second line contains .
Output
Print the number of -tuples of hunger levels modulo .