#C5988. Pair with Sum
Pair with Sum
Pair with Sum
You are given an array of N integers and an integer K. Your task is to determine whether there exist two distinct indices i and j such that:
$$A[i] + A[j] = K$$
If such a pair exists, print YES
; otherwise, print NO
. The array may contain negative numbers and duplicate values.
inputFormat
The first line contains two integers N
and K
, where N
is the number of elements in the array and K
is the target sum.
The second line contains N
space-separated integers representing the array A
.
You should read input from stdin.
outputFormat
Print a single line to stdout containing YES
if there exists a pair of distinct indices i
and j
such that A[i] + A[j] = K
, or NO
otherwise.
4 7
1 2 3 4
YES
</p>