#K54172. Pair with Given Difference

    ID: 29695 Type: Default 1000ms 256MiB

Pair with Given Difference

Pair with Given Difference

Given an array of integers and an integer k, determine if there exist two distinct indices i and j in the array such that \( |a[i]-a[j]| = k \). If such a pair exists, print "Yes"; otherwise, print "No". The absolute difference is defined as \( |x| \). Your task is to implement an efficient algorithm to solve this problem.

Note: Try to achieve an algorithm with linear complexity using appropriate data structures.

inputFormat

The input is read from standard input (stdin). It begins with an integer T (the number of test cases). For each test case:

  1. The first line contains two space-separated integers, n and k, where n is the number of elements in the array and k is the target difference.
  2. The second line contains n space-separated integers representing the array elements.

outputFormat

For each test case, output a single line to standard output (stdout) containing "Yes" if there exists at least one pair of elements with an absolute difference equal to k, and "No" otherwise.

## sample
5
5 2
1 5 3 4 2
4 0
7 7 7 7
6 4
8 12 16 4 0 20
3 5
1 2 8
5 10
1 2 3 4 5
Yes

Yes Yes No No

</p>