#C10712. Pair Sum Existence
Pair Sum Existence
Pair Sum Existence
This problem requires you to determine whether there exists a pair of integers in a given array whose sum equals a given target value \(S\). You are given an array of \(n\) integers and a target sum. Your task is to check if any two distinct elements in the array add up exactly to \(S\).
Input Format:
The input is read from standard input (stdin) and is structured as follows:
- The first line contains an integer \(T\), the number of test cases.
- For each test case:
- The first line contains an integer \(n\), the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the elements of the array. If \(n = 0\), this line will be empty.
- The third line contains the target integer \(S\).
Output Format:
For each test case, output a single line with either "YES" if there exists at least one pair of numbers that add up to \(S\), or "NO" if no such pair exists.
Example:
Output:Input:
2
6
1 4 45 6 10 -8
16
4
1 2 3 9
8
YES
NO
inputFormat
The first line contains an integer \(T\) representing the number of test cases. Each test case consists of three lines:
- An integer \(n\) representing the size of the array.
- \(n\) space-separated integers representing the array elements. (If \(n=0\), this line will be empty.)
- An integer \(S\), the target sum.
outputFormat
For each test case, output a single line: "YES" if there exists a pair of distinct integers in the array whose sum equals \(S\), otherwise output "NO".
## sample10
6
1 4 45 6 10 -8
16
4
1 2 3 9
8
6
7 1 5 3 6 2
9
4
1 3 4 5
7
0
5
1
1
1
3
2 2 2
4
2
0 0
0
4
-1 -2 -3 -4
-3
4
1 2 3 9
12
YES
NO
YES
YES
NO
NO
YES
YES
YES
YES
</p>