#C6559. Pair Sum Detection

    ID: 50332 Type: Default 1000ms 256MiB

Pair Sum Detection

Pair Sum Detection

Given an array of n integers and a target sum \(T\), determine whether there exists a pair of distinct elements in the array whose sum is exactly \(T\).

The program reads from standard input and writes to standard output. It should print YES if such a pair exists, or NO otherwise. The solution must correctly handle edge cases involving negative numbers and arrays with a single element.

inputFormat

The input is provided via standard input in the following format:

N
a1 a2 ... aN
T

Where:

  • N is the number of elements in the array.
  • a1, a2, ..., aN are the space-separated integers of the array.
  • T is the target sum.

outputFormat

Output a single line via standard output:

YES

If there exists a pair of distinct elements whose sum is \(T\), and NO otherwise.

## sample
5
1 2 3 4 5
9
YES