#K53057. Pair with Sum
Pair with Sum
Pair with Sum
Given an array of integers and a target sum \(M\), determine whether there exists a pair of distinct elements in the array that add up to \(M\). This problem requires you to find two indices \(i\) and \(j\) (with \(i \neq j\)) such that:
\(a_i + a_j = M\)
You will be given multiple test cases. For each test case, if such a pair exists, print YES
; otherwise, print NO
.
inputFormat
The first line of input contains a single integer \(T\) representing the number of test cases. Each test case is described as follows:
- The first line of each test case contains two integers \(N\) and \(M\), where \(N\) is the number of elements in the array, and \(M\) is the target sum.
- The second line contains \(N\) space-separated integers representing the array elements.
Input is provided via stdin
.
outputFormat
For each test case, output a single line containing either YES
or NO
on stdout
depending on whether a valid pair exists.
3
6 10
1 2 3 4 5 6
4 5
1 1 1 1
5 9
2 7 11 15 3
YES
NO
YES
</p>