#K36027. Pair Sum Problem

    ID: 25663 Type: Default 1000ms 256MiB

Pair Sum Problem

Pair Sum Problem

You are given an integer T denoting the number of test cases. For each test case, you are provided with an integer N representing the size of an array, an integer X indicating a target sum, and an array of N integers. The task is to determine if there exists a pair of distinct elements in the array whose sum equals X.

More formally, given an array \(A = [a_1, a_2, \dots, a_N]\) and a target sum \(X\), you need to check whether there exist two indices \(i, j\) with \(i \neq j\) such that:

[ a_i + a_j = X ]

If such a pair exists, output YES; otherwise, output NO. Your solution should read input from stdin and print the output to stdout.

inputFormat

The input is read from stdin and has the following structure:

  1. The first line contains an integer (T) (the number of test cases).
  2. For each test case:
    • The first line contains two integers (N) and (X), where (N) is the number of array elements and (X) is the target sum.
    • The second line contains (N) space-separated integers representing the array elements.

For example:

3
5 9
1 2 3 4 5
4 8
2 3 5 7
3 10
1 2 4

outputFormat

For each test case, print a single line to stdout with either YES if there exists a pair of distinct array elements whose sum equals (X), or NO otherwise.

For instance, for the sample input above, the expected output is:

YES
YES
NO
## sample
3
5 9
1 2 3 4 5
4 8
2 3 5 7
3 10
1 2 4
YES

YES NO

</p>