Sweets
Time limit1sMemory limit128 MB
Count the ways to take up to m_i candies from each of n jars so the total is between a and b, modulo 2004.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Prefix sum, Combinatorics, Math
- Solved
- No attempts yet
Problem
John has jars of candies. Each jar holds a distinct kind of candy (all candies in one jar are of the same kind, and candies from different jars are of different kinds). The -th jar contains candies.
John wants to eat some of his candies — at least but no more than in total. From each jar he may take any number of candies between and inclusive. Two ways of eating are different if they differ in the number of candies taken from at least one jar.
Count the number of ways John can choose the candies to eat so that the total eaten is at least and at most . Since this number can be large, output it modulo .
Input
The first line contains three integers , , and separated by single spaces (, ). Each of the next lines contains one integer; line contains , the number of candies in the -th jar ().
Output
Let be the number of ways John can choose the candies to eat. Output a single integer: (the remainder of divided by ).
Hint
In the sample the two jars hold and candies, and the total eaten must satisfy . Writing each way as (candies taken from jar 1, candies taken from jar 2), the valid ways are: