#K201. Two Sum Problem

    ID: 24641 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

Given an array of integers and a target integer k, determine whether there exist two distinct indices i and j such that \(a_i + a_j = k\). In other words, you need to check if there is a pair of different elements in the array whose sum equals k.

If such a pair exists, output YES; otherwise, output NO. Note that an element cannot be used twice.

Example:

  • For the array [2, 7, 11, 15] and k = 10, no pair sums up to 10, so the answer is NO.
  • For the array [1, 2, 3, 4, 5] and k = 7, pairs like (2, 5) or (3, 4) sum to 7, so the answer is YES.

inputFormat

The input is given via stdin and is formatted as follows:

  1. The first line contains two integers n and k, where n denotes the number of elements in the array and k is the target sum.
  2. The second line contains n integers separated by spaces representing the elements of the array. If n = 0, the second line will be empty.

outputFormat

The output should be printed to stdout as a single line containing either YES or NO depending on whether a valid pair exists.

## sample
4 10
2 7 11 15
NO