~/algor $ cat problems/ikki-korsatkich-eng-yaqin-yigindi
Pair with sum closest to x
Medium
1000 ms
128 MB
45%
$n$ integers sorted in non-decreasing order and an integer $x$ are given. Choose two elements at different positions ($i \lt j$) so that their sum $a_{i} + a_{j}$ is as close to $x$ as possible. Print this sum. If two sums are equally close to $x$, print the smaller one.
Input
The first line contains two integers: $n$ and $x$. The second line contains $n$ integers $a_{i}$ in non-decreasing order.
Output
One integer — the sum closest to $x$.
Note
$2 \le n \le 2 * 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$
$-2 * 10^{9} \le x \le 2 * 10^{9}$
Examples
Input #1
5 10 1 3 4 7 12
Output #1
10
Input #2
3 6 1 4 6
Output #2
5