#C4893. Find Pair with Given Sum
Find Pair with Given Sum
Find Pair with Given Sum
You are given an array of integers and a target sum. Your task is to determine whether there exists a pair of distinct elements in the array whose sum is equal to the target.
If such a pair exists, print YES
; otherwise, print NO
.
Note: Each element in the array can be used at most once in forming the pair. The solution should be efficient and consider various edge cases.
Mathematically, you need to check if there exist distinct indices \(i\) and \(j\) such that \(a_i + a_j = target\).
inputFormat
The input is read from standard input (stdin). The first line contains two integers, \(n\) (the number of elements in the array) and \(target\) (the target sum), separated by a space.
The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Output a single line to standard output (stdout) containing either YES
if there exists a pair whose sum equals the target, or NO
otherwise.
5 9
1 2 3 4 5
YES