#C5483. Find Pair with Exact Difference

    ID: 49137 Type: Default 1000ms 256MiB

Find Pair with Exact Difference

Find Pair with Exact Difference

You are given an array of integers and an integer target. Your task is to determine whether there exist two distinct indices \( i \) and \( j \) in the array such that the absolute difference of the corresponding elements is exactly equal to target, i.e. \(|a_i - a_j| = target\).

For example, given an array [1, 5, 3, 4, 7] and target = 2, one possible pair is (1, 3) because \(|1 - 3| = 2\), so the answer is YES. If no such distinct pair exists, print NO.

Implement a solution that reads multiple test cases from standard input and writes the result for each test case to standard output.

inputFormat

The first line contains an integer T representing the number of test cases.

For each test case, the input is as follows:

  • The first line contains an integer n, the number of elements in the array.
  • The second line contains n space-separated integers representing the array.
  • The third line contains a single integer target.

You need to process each test case and output the result on a new line.

outputFormat

For each test case, output a single line containing YES if there exist two distinct indices \( i \) and \( j \) such that \(|a_i - a_j| = target\); otherwise, output NO.

## sample
1
5
1 5 3 4 7
2
YES

</p>