Find the missing rank
Time limit2sMemory limit32 MB
Count score assignments within given ranges where no person receives rank R under tied ranking.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
people take a mock exam whose maximum score is . Keunwoo roughly knows how strong they are, so he expects person to score at least and at most .
The exam is graded on a curve, so once it is over every person gets a rank between and . A person's rank is the number of people with a strictly higher score, plus .
If and and the five people score 6, 5, 3, 9 and 5, their ranks are 2, 3, 5, 1 and 3 in that order. Because of the tie, nobody gets rank 4.
For his favourite number , Keunwoo wants to know how many outcomes leave rank empty. An outcome gives every person one score inside their own range, and two outcomes are different if at least one person's score is different.
Input
The first line contains the number of people and the maximum score . Each of the next lines contains the score range and of person . The last line contains Keunwoo's favourite number .
, , ,
Output
Print the number of outcomes in which nobody gets rank , modulo 1,000,000,007 ().
Hint
Take , , the four ranges 1 to 3, 2 to 4, 3 to 5 and 4 to 6, and . Splitting by the scores of people 1, 2 and 3, the outcomes without a rank 4 are:
- people 1 and 2 score 2: 9 outcomes
- people 1 and 2 score 3 and person 3 scores at least 4: 6 outcomes
- people 1 and 3 score 3 and person 2 scores 4: 3 outcomes
- people 1, 2 and 3 all score 3: 3 outcomes
So 21 outcomes leave rank 4 empty.