Problem C: Counting Problem C: Counting
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 1599 Solved: 216
[Submit][Status][Web Board]Description
Give you an increasing sequence A of length n, and find the number of ordered tuples (i, j, k) such that the maximum element in {A[i], A[j], A[k]} minus the minimum element in {A[i], A[j], A[k]} <= m.
Input
The first line of the input is T (T <= 5), which is the number of test cases.
For each test cases, the first line is n, m, the next line contains n integers which is the given sequence A. (1 ≤ n ≤ 100000 ; 1 ≤ m≤ 1000000000) abs(A[i] <= 1000000000).
Output
For each test cases, print the number of tuples satisfying requirements in one line.
Sample Input
2
4 3
1 2 3 4
5 19
1 10 20 30 50
Sample Output
4
1
HINT
[Submit][Status]