#C6488. Pair Sum Existence

    ID: 50253 Type: Default 1000ms 256MiB

Pair Sum Existence

Pair Sum Existence

You are given an array of n integers and an integer k. Your task is to determine whether there exists a pair of distinct elements in the array such that their sum equals k.

In mathematical terms, given an array \(a_1, a_2, \dots, a_n\) and an integer \(k\), determine if there exist indices \(i\) and \(j\) with \(i \neq j\) such that:

\[ a_i + a_j = k \]

An efficient approach involves using a hash set. As you process each number, check whether \(k - x\) has already been seen. If yes, output YES; otherwise, continue to process the rest of the array. If no such pair exists, output NO.

inputFormat

The input is given in standard input and consists of two lines:

  • The first line contains two integers n and k separated by a space, where \(1 \le n \le 10^5\).
  • The second line contains n space-separated integers representing the elements of the array.

outputFormat

Output YES if there exists a pair of elements whose sum equals k; otherwise, output NO. The result should be printed on the standard output.

## sample
5 9
2 7 11 15 3
YES