#K73292. Has Pair with Sum
Has Pair with Sum
Has Pair with Sum
You are given an array B containing M integers and an integer target K. Your task is to determine whether there exist two distinct elements in B whose sum is equal to K. In other words, check if there exist two indices i and j (i \neq j) such that
$$B_i + B_j = K$$
If such a pair exists, print YES
; otherwise, print NO
.
Note: Even if the same number appears more than once in the array, the pair must consist of two different elements (i.e. from two different positions).
inputFormat
Input is given via standard input (stdin). The first line contains two integers M and K, where M is the number of elements in the array and K is the target sum. The second line contains M space-separated integers representing the array B.
outputFormat
Output the string YES
if there exists a pair of distinct elements in B whose sum is K, otherwise output NO
. The output should be written to standard output (stdout).## sample
5 8
2 4 3 5 7
YES
</p>