#K48432. Find a Pair with Given Sum

    ID: 28419 Type: Default 1000ms 256MiB

Find a Pair with Given Sum

Find a Pair with Given Sum

You are given an array of integers and a target sum \(S\). Your task is to determine whether there exists a pair of distinct elements in the array whose sum is exactly equal to \(S\). Formally, given an array \(a[1\ldots n]\) and an integer \(S\), determine if there exist indices \(i\) and \(j\) (with \(i \neq j\)) such that:

\(a[i] + a[j] = S\)

If such a pair exists, print YES; otherwise, print NO. Only one valid pair is needed to produce the answer.

inputFormat

The input is provided via standard input (stdin) in the following format:

  1. The first line contains an integer \(n\) representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers, which are the elements of the array.
  3. The third line contains an integer \(S\), the target sum.

outputFormat

Output a single line to standard output (stdout) containing YES if there exists a pair of distinct elements whose sum is equal to the target \(S\); otherwise, output NO.

## sample
5
1 2 3 4 5
9
YES

</p>