#K44127. Pair with Target Sum

    ID: 27463 Type: Default 1000ms 256MiB

Pair with Target Sum

Pair with Target Sum

Given an array of integers and an integer \(k\), determine whether there exist two distinct elements in the array whose sum is exactly \(k\). This is a variant of the classic two-sum problem.

The goal is to check if there exists any pair \(a\) and \(b\) in the array such that

[ a + b = k ]

with \(a\) and \(b\) being distinct elements. An efficient solution with linear time complexity is expected.

inputFormat

The input consists of multiple test cases. The first line of input contains an integer \(T\) representing the number of test cases. Each test case is described 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 an integer \(k\), the target sum.

outputFormat

For each test case, output a single line containing either "YES" if there exists a pair of distinct elements that sum up to \(k\), or "NO" otherwise.

## sample
2
4
10 15 3 7
17
5
1 2 3 9 11
8
YES

NO

</p>