#K51162. Pair with Given Sum
Pair with Given Sum
Pair with Given Sum
You are given an array of integers and a target integer \(T\). Your task is to determine if there exist two distinct elements in the array such that their sum is exactly \(T\). In other words, if the array is \(a_1, a_2, \dots, a_n\), you need to check if there exist indices \(i\) and \(j\) (with \(i \neq j\)) such that \(a_i + a_j = T\).
If such a pair exists, output YES
; otherwise, output NO
.
Note: The array may contain duplicate values, but the two numbers chosen to form the sum must come from distinct positions in the array.
inputFormat
The input consists of three lines:
- The first line contains an integer (n) which is the number of elements in the array.
- The second line contains (n) space-separated integers representing the array elements.
- The third line contains a single integer (T), the target sum.
outputFormat
Output a single line containing YES
if there exist two distinct elements in the array whose sum is equal to (T). Otherwise, output NO
.## sample
5
1 2 3 7 8
10
YES
</p>