Kebab House
Time limit2sMemory limit256 MB
Count subsets of the work seconds with gaps of at least t+1 such that each kebab misses at most q_i minus x_i ingredients, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
Vahtang Bumerang makes kebabs at the fast food chain Kebab House. One kebab holds many ingredients.
This morning Vahtang got an order for kebabs. He puts ingredients into the first kebab, then ingredients into the second one, and so on in that order. Putting in one ingredient takes exactly one second, so the -th kebab takes seconds, and he starts the next kebab the moment he finishes one. The whole job therefore runs without a break for seconds, numbered 1, 2, 3 and so on from the moment he starts.
While he works, Vahtang keeps thinking of his beloved boomerang and drifts into a daydream. Each dream lasts exactly one second, and during that second he forgets to put in an ingredient. He never dreams twice inside any consecutive seconds, so the numbers of two dream seconds always differ by at least .
Because of the dreams a kebab can end up with fewer ingredients than intended. Customer is happy when the -th kebab holds at least ingredients.
Compute the number of ways to choose the dream seconds so that every customer is happy, modulo . Two ways count as different when the sets of dream seconds differ.
Input
The first line contains the number of kebabs and the value that sets the minimum spacing between dream seconds (, ).
The -th of the next lines contains , the number of ingredients meant for the -th kebab, and , the smallest number of ingredients that makes the -th customer happy (, ).
Output
Print on one line the number of ways to choose the dream seconds so that every customer is happy, modulo .