#K40332. Pair with Given Sum
Pair with Given Sum
Pair with Given Sum
Given an integer target and a list of integers, determine whether there exists a pair of distinct indices \(i\) and \(j\) such that:
[ a_i + a_j = \text{target} ]
If such a pair exists, print YES
; otherwise, print NO
.
Note: Each pair must consist of two different elements. In other words, you cannot use the same array element twice.
inputFormat
The input is given via STDIN and has the following format:
- The first line contains an integer target.
- The second line contains an integer n representing the number of elements in the array.
- The third line contains n space-separated integers.
outputFormat
Output a single line to STDOUT containing either YES
if there exists a pair of distinct elements \(a_i\) and \(a_j\) such that \(a_i + a_j = \text{target}\), or NO
otherwise.
5
5
1 2 3 4 5
YES