Closest Pair Sum
Choose two different elements whose sum is as close as possible to the target T. Print that sum; if two sums are equally close, print the smaller sum.
Input: the first line has N and T; the second line has N integers.
Output: the achievable pair sum closest to T (smaller one on ties).
Constraints:
- 2 ≤ N ≤ 105
- |ai|, |T| ≤ 2×109
Sample Tests
Input 1
5 10 1 3 5 8 12
Output 1
9
Input 2
2 0 -3 9
Output 2
6
Discussion (opens after you solve — no spoilers before)
No comments yet.