#K48432. Find a Pair with Given Sum
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:
- The first line contains an integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers, which are the elements of the array.
- 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.
## sample5
1 2 3 4 5
9
YES
</p>