#K65047. Check Pairs with Specified Difference

    ID: 32110 Type: Default 1000ms 256MiB

Check Pairs with Specified Difference

Check Pairs with Specified Difference

You are given an integer \( T \) representing the number of test cases. Each test case consists of an integer \( n \) and an integer \( k \) on the first line, followed by \( n \) integers on the next line representing the array. Your task is to determine for each test case whether there exists a pair of distinct indices \( i \) and \( j \) such that \(|A_i - A_j| = k\).

If such a pair exists, print YES; otherwise, print NO.

Input Format:

  • The first line contains an integer \( T \) denoting the number of test cases.
  • For each test case, the first line contains two integers \( n \) and \( k \).
  • The second line contains \( n \) integers representing the array.

Output Format:

  • For each test case, output a single line containing either YES or NO based on whether such a pair exists.

Example:

Input:
3
5 3
1 5 3 4 2
4 0
1 2 3 4
3 1
-1 0 1

Output: YES NO YES

</p>

inputFormat

The input begins with an integer \( T \) representing the number of test cases. For each test case, the first line contains two space-separated integers \( n \) (the size of the array) and \( k \) (the target difference). The second line contains \( n \) space-separated integers.

outputFormat

For each test case, output one line containing YES if there exists a pair of distinct indices \( i \) and \( j \) such that \(|A_i - A_j| = k\), otherwise output NO.

## sample
3
5 3
1 5 3 4 2
4 0
1 2 3 4
3 1
-1 0 1
YES

NO YES

</p>