#C895. Two Elements Sum Problem
Two Elements Sum Problem
Two Elements Sum Problem
Given an array of N integers and an integer K, determine whether there exist two distinct elements in the array whose sum is exactly K
. Formally, find if there exist indices i and j with i ≠ j such that
\(a_i + a_j = K\)
Output YES
if such a pair exists, or NO
otherwise.
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains two integers
N
andK
, whereN
is the number of elements in the array. - The second line contains
N
space-separated integers representing the array.
outputFormat
Output a single line to the standard output: YES
if there exists a pair of distinct elements whose sum is K
; otherwise, output NO
.
5 9
2 7 11 15 1
YES