#C2013. Pair with Given Sum

    ID: 45283 Type: Default 1000ms 256MiB

Pair with Given Sum

Pair with Given Sum

You are given an array A of n integers and a target integer k. Your task is to determine whether there exist two distinct elements in the array such that their sum is equal to k. In other words, find two indices i and j (with i \neq j) for which

\(A_i + A_j = k\)

If such a pair exists, print YES; otherwise, print NO.

The problem requires an efficient solution. Typical approaches involve the use of a hash set or sorting with two pointers.

inputFormat

The input is given via standard input (stdin) and consists of:

  1. An integer n, the number of elements in the array.
  2. A line with n space-separated integers representing the array A.
  3. An integer k on a new line, the target sum.

outputFormat

Output a single line to standard output (stdout) containing either YES if there exists a pair such that their sum is equal to k, or NO otherwise.

## sample
5
1 3 4 5 6
9
YES