eolymp
bolt
Try our new interface for solving problems
Problems

The best team

The best team

$n$ programmers gathered today. Every programmer has a rating showing his strength. Rating is an integer from $0$ to $10^9$. Your rating as a programmer is $m$. From all the programmers gathered today, you want to choose two for your team. They should be chosen so that the sum of their ratings is maximum, but this sum should not exceed your rating, since you want to be the head of this team. \InputFile The first line contains two integers: $n~(2 \le n \le 10^5)$ --- the number of programmers and $m~(0 \le m \le 10^9)$ --- your rating. The second line contains $n$ integers $r_1, r_2, ... , r_n~(0 \le r_i \le 10^9)$, the ratings of programmers. \OutputFile Print one integer --- the sum of the ratings of the selected programmers, or $-1$ if it is impossible to find such two people.
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 8
5 3 4 6 5
Output example #1
8
Input example #2
7 19
8 4 25 1 20 5 12
Output example #2
17
Input example #3
4 76
38 41 39 40
Output example #3
-1