Was the 2022 APC really that hard?
InterviewTime limit1sMemory limit1024 MB
Count the sequences of N difficulties where each D_i lies in [a_i, b_i] and adjacent values differ by at most K, modulo 1e9+7.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Prefix sum
- Solved
- No attempts yet
Problem
In 2022, the APC was harder than the problem setters expected. To control difficulty, Hyeonbin, a setter for the 2023 APC, wrote a difficulty guideline. The 2023 APC will have problems, numbered 1 through in order.
Hyeonbin's guideline has two rules.
- The difficulty of problem is an integer that satisfies .
- The difficulty gap between adjacent problems is at most . In other words, holds for every .
For Hyeonbin, count the number of ways to set the difficulties of the problems while following the guideline's rules.
Input
The first line contains and .
From the second line onward, the next lines each contain and , separated by a space.
All values in the input are integers.
Output
Print the number of ways to set the difficulties of the problems that satisfy the conditions, modulo .
Hint
Sorry about that.