#C3170. Counting Pairs with Given Difference
Counting Pairs with Given Difference
Counting Pairs with Given Difference
You are given an array of integers and an integer (D). For each test case, your task is to count the number of pairs ((i, j)) such that the absolute difference (|a_i - a_j|) is exactly (D), and where the element at index (i) appears before the element at index (j) in the array.
Each test case begins with two integers (N) and (D), where (N) denotes the number of elements in the array and (D) is the desired difference. The next line contains (N) space-separated integers. Your program should output the count for each test case on a separate line.
inputFormat
The input is given via standard input (stdin) and has the following format:
(T) (\newline)
For each test case:
(N) (D) (\newline)
(a_1\ a_2\ \dots\ a_N)
outputFormat
For each test case, output a single line containing the number of valid pairs. The output should be written to standard output (stdout).## sample
2
5 2
1 5 3 4 2
3 0
1 1 1
3
3
</p>