Competitions
Техника двух указателей
Two sum
Given a sorted array A in ascending order, having n integers. Find if there exists any pair of elements (Ai
, Aj
), i < j, such that their sum is equal to x.
Input
The first line contains two integers n (n ≤ 105
) and x (x ≤ 106
). Second line contains n nonnegative integers, each no more than 106
.
Output
Print "YES" if such pair of elements exists, and "NO" otherwise.
Input example #1
10 13 1 3 5 6 8 10 11 11 11 16
Output example #1
YES
Input example #2
8 61 5 5 8 12 16 21 44 50
Output example #2
NO