Leaderboard
Showing:
Count Number
Medium Accuracy: 14.65% Submissions: 672 Points: 4

Given an array A consisting of integers of size N and 2 additional integers K and X, you need to find the number of subsets of this array of size K, where Absolute difference between the Maximum and Minimum number of the subset is at most X.

As this number that you need to find can be rather large, print it Modulo 109+7


Input:
The first line of input contains T denoting the no of test cases . Then T test cases follow . The first line of each test case contains
3 space separated integers denoting N, K and X. The next line contains N space separated values of the array A[ ] .

Output:
For each test case output the required result in a new line, print it Modulo 109+7.

Constraints:

1≤N≤5×105
1≤K≤N
1≤A[i],X≤109

Example:
Input:

2
5 3 5
1 2 3 4 5
8 4 6
2 4 6 8 10 12 14 16
Output:
10
5

Explanation :
For the first test case

Possible subsets of size 3 are {1,2,3} {1,2,4} {1,2,5} {1,3,4} {1,3,5} {1,4,5} {2,3,4} {2,3,5} {2,4,5} {3,4,5} having difference of maximum and minimum element less than equal to 5.

For the second test case
Possible subsets of size 4 are {2,4,6,8} {4,6,8,10} {6,8,10,12} {8,10,12,14} {10,12,14,16} having difference of maximum and minimum element less than equal to 6.

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Count Number

Output Window