LogiQuest

180. Pair Sum Closest to Target

MediumTwo Pointers

Print the pair sum (two different positions) closest to the target. If two sums are equally close, print the smaller sum.

Input format

Line 1: n target Line 2: n integers

Output format

The closest sum.

Example 1

Input

5 54
10 22 28 29 30

Output

52

Example 2

Input

4 15
1 3 4 7

Output

11

Constraints

2 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…