Stone

시간 제한1.5초메모리 제한1024 MB

요약
각 더미의 초기 돌 개수를 주어진 범위에서 고르고 k개의 돌을 더 분배한 뒤, 두 가지 제거 연산으로 모든 돌을 없앨 수 있는 경우의 수를 센다.
난이도

어려움10점 중 8점

유형
동적 계획법, 그리디, 수학, 조합론
정답자
아직 제출이 없습니다

문제

You are playing a game called "Remove Stones". There are nn piles of stones lined up in a row, the ii-th pile has a_ia\_i stones in it, your task is to remove all the stones through the following operations:

  • Select a pile of stones and remove at least 22 stones;
  • Select a contiguous interval \[l,r]\[l, r] (1≤l≤r≤n1 \leq l \leq r \leq n) which satisfies r−l≥2r - l \geq 2 , remove exactly 1 stone from each pile in the interval.

You can perform the above two operations any number of times in any order until you can no longer perform the operations. If you can remove all the stones, you win.

You have kk stones secretly hidden in the beginning, you must put these stones into a certain pile or in some piles of stones before the game starts. You can choose any configuration of putting in the kk extra stones. For each pile, there is a range that the number of stones in it must lie in, specifically, each a_ia\_i can be chosen from any integer in the range \[l_i,r_i]\[l\_i, r\_i]. Find the number of winning configurations modulo (109+7)(10^9 + 7).

Two configurations are different if and only if there exists at least one ii (1≤i≤n1 \leq i \leq n) such that a_ia\_i differs in the two initial configurations. Here, "initial configurations" refer to the configuration before putting the kk stones into the piles.

입력

The first line is an integer TT, the number of subcases in the data.

For each test case, there are two integers nn and kk in the first line, representing the number of piles of stones and the number of stones added, respectively, and the next nn lines, each with two non-negative integers l_il\_i and r_ir\_i, represent the range of the initial number of stones in each pile of stones.

출력

For each test case, output a line with an integer denoting the number of winning initial positions modulo 109+710^9+7.

제한

For all test cases, T≤10T \leq 10, 3≤n≤10003 \leq n \leq 1000, 0≤l_i≤r_i≤1090 \leq l\_i \leq r\_i \leq 10^9, 0≤k≤1000 \leq k \leq 100.

예제1

  1. 예제 1

    입력
    1
    4 1
    0 1
    0 1
    0 1
    0 1
    
    예상 출력
    14