#K44497. Pair with Given Sum
Pair with Given Sum
Pair with Given Sum
Given a list of n integers and a target sum x, determine whether there exist two distinct indices i and j such that
\(a[i] + a[j] = x\)
The input is given in two lines. The first line contains two integers: n (the number of elements) and x (the target sum). The second line contains n space-separated integers representing the list.
The output should be a single line containing YES
if such a pair exists, and NO
otherwise.
inputFormat
The first line of input contains two integers n
and x
separated by a space.
The second line contains n
space-separated integers, representing the array a
.
outputFormat
Output a single line: YES
if there exist two distinct indices such that their sum is x
, otherwise NO
.
5 9
1 2 3 4 5
YES