Count score assignments within given ranges where no person receives rank R under tied ranking.
Hard8Dynamic programmingCombinatoricsPrefix sumNo attempts yetTime limit2sMemory limit32 MBN people take a mock exam whose maximum score is M. Keunwoo roughly knows how strong they are, so he expects person k to score at least Ak and at most Bk.
The exam is graded on a curve, so once it is over every person gets a rank between 1 and N. A person's rank is the number of people with a strictly higher score, plus 1.
If N=5 and M=10 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 R, Keunwoo wants to know how many outcomes leave rank R 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.
The first line contains the number of people N and the maximum score M. Each of the next N lines contains the score range Ak and Bk of person k. The last line contains Keunwoo's favourite number R.
1≤N≤250, 1≤M≤400, 0≤Ak≤Bk≤M, 1≤R≤N
Print the number of outcomes in which nobody gets rank R, modulo 1,000,000,007 (109+7).
Take N=4, M=6, the four ranges 1 to 3, 2 to 4, 3 to 5 and 4 to 6, and R=4. Splitting by the scores of people 1, 2 and 3, the outcomes without a rank 4 are:
So 21 outcomes leave rank 4 empty.