#K96347. Find Pair with Difference

    ID: 39066 Type: Default 1000ms 256MiB

Find Pair with Difference

Find Pair with Difference

You are given t test cases. In each test case, you are provided with two integers: n (the number of elements in the array) and k (the required absolute difference). This is followed by an array of n distinct integers. Your task is to determine whether there exists a pair of elements in the array such that the absolute difference between them is exactly k.

Formally, for a given array \(A\) of \(n\) integers, check if there exist two indices \(i\) and \(j\) (with \(i \neq j\)) such that \(|A[i] - A[j]| = k\). If such a pair exists, print YES; otherwise, print NO.

Note: The absolute difference is defined as \(|x| = \begin{cases} x, & x \ge 0 \\ -x, & x < 0 \end{cases}\).

inputFormat

The input begins with a single integer t representing the number of test cases. Each test case is described in two lines:

  • The first line contains two integers n and k.
  • The second line contains n space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single line containing YES if there exists at least one pair of elements in the array with an absolute difference of exactly k, otherwise output NO.

## sample
3
5 2
1 5 3 4 2
4 7
10 15 20 25
5 1
3 8 2 1 6
YES

NO YES

</p>