P20544 [HackerEarth] Roger is a robot. He has n different arms. Currently, his arms are extended out on a 1 dimensional line. The i-th arm is currently extended ai units to the right. It is guaranteed that 0
提高
题目描述

Roger is a robot. He has n different arms. Currently, his arms are extended out on a 1 dimensional line. The i-th arm is currently extended ai units to the right. It is guaranteed that 0 < a1 < a2 < ... < an.

Roger would like to retract his arms so that his i-th arm is extended bi units to the right. It is guaranteed that 0 < b1 < b2 < ... < bn and that bi ≤ ai.

In one second, Roger can choose any subset of his arms (including the empty set), and retract the chosen subset by one unit to the left. More specifically, this means subtracting one from the coordinates of each of the chosen arms. In addition, he doesn't like his arms getting tangled, so at each intermediate time step, the coordinates of his arms must be in strictly increasing order.

Roger has K seconds to get to the final position. Help him count the number of ways he can do this. Two ways are different if there exists a second in which Roger chose a different set of arms. Since the number of ways can get very large, return the count modulo 1,000,000,007.

Input Format
The first line of the input will contain an integer T, denoting the number of test cases.
Each test case will be formatted as follows:
The first line of the test case will contain 2 integers, n, K.
The second line of the test case will contain n integers, a1,...,an
The third line of the test case will contain n integers, b1,...,bn

Output Format
Print a single line per test case, the number of ways for Roger to get to the final position, modulo 1,000,000,007.

Constraints
For all files
1 ≤ T ≤ 20
1 ≤ n
1 ≤ K ≤ 1,000,000
1 ≤ bi ≤ ai ≤ 1,000,000
The sequences ai and bi are in strictly increasing order.

File 1 -- 50 pts:
n = 1

File 2 -- 23 pts:
n = 2

File 3 -- 15 pts:
n ≤ 5

File 4 -- 12 pts:
n ≤ 50

SAMPLE INPUT
5
1 3
10
3
1 4
6
3
2 3
3 4
1 2
2 10
10 20
5 10
25 1000000
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

SAMPLE OUTPUT
0
4
6
252
929952727

Explanation

In the first sample case, we need to retract the arm from 10 to 3, which is a total of 7 units, but we only have 3 seconds to do so. There is no way for Roger to reach his goal in this case.

In the second sample case, Roger needs to move his arm from 6 to 3. We have 4 seconds to do so. Thus, Roger can choose exactly 1 out of the 4 seconds to rest and still reach the goal.

In the third sample case, Roger has two arms. The first is pointing at coordinate 3, and the second is pointing at coordinate 4. He would like to move them so the first one is at coordinate 1, and the second is at coordinate 2. The 6 ways are
(3,4) -> (3,4) -> (2,3) -> (1,2)
(3,4) -> (2,3) -> (2,3) -> (1,2)
(3,4) -> (2,3) -> (1,2) -> (1,2)
(3,4) -> (2,4) -> (2,3) -> (1,2)
(3,4) -> (2,4) -> (1,3) -> (1,2)
(3,4) -> (2,3) -> (1,3) -> (1,2)

Note that the way (3,4) -> (3,3) -> (2,3) -> (1,2) is not valid. In the second step, Roger's arms will get tangled as they are no longer in increasing order.

Don't forget to take the answer modulo 1,000,000,007.

输入格式

见题面

输出格式

见题面

样例输入
20 2 992796 584628 973058 428149 968328 2 801966 733965 953672 433968 653386 2 965819 504685 929841 383606 789680 2 945923 425961 965076 290585 567845 2 607698 388613 605649 77244 199573 2 540674 585990 833465 413994 782792 2 693326 889851 989841 345792 781784 2 562680 557139 593157 343472 447674 2 915276 840214 919668 649178 882167 2 108323 440855 691555 392571 672973 2 686489 938439 949551 645339 747723 2 835879 941393 948627 501231 899999 2 461626 540869 587115 210615 540972 2 579159 699886 929198 291032 412897 2 498877 871282 989907 670397 923176 2 625395 262916 500816 14443 89621 2 558480 377090 447645 206576 329950 2 200 194381 990466 123231 984916 2 341915 586172 848949 364834 614264 2 691223 911366 981300 516283 978416
样例输出
700302565 254987241 823040724 788630106 1883472 422366620 198773553 787714166 380056093 477487729 585401171 241406913 683714927 663611666 415531011 254872854 963381557 0 746211690 700961908