Count Number
Submissions: 497   Accuracy:

14.86%

  Difficulty: Medium   Marks: 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.

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal
Author: Amit Khandelwal 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.