Two Gifts
InterviewTime limit1sMemory limit1024 MB
Given n gift prices and a budget x, find the largest sum of two different gifts that does not exceed x.
- Level
Easy3 of 10
- Topics
- Two pointers, Sorting
- Solved
- No attempts yet
문제
Senya is choosing New Year gifts. Ded Moroz will buy him exactly two gifts, one that is supposedly from his mom and another that is supposedly from his dad.
The store sells gifts, and the price of the -th gift is rubles. Ded Moroz can spend at most rubles on the two gifts. Senya wants the most expensive pair possible, so he needs to choose two different gifts with the maximum total price that does not exceed .
Help Senya choose his gifts.
입력
The first line contains two integers and (, ). The second line contains integers (). It is guaranteed that there are two gifts whose total price does not exceed .
출력
Print one integer: the maximum total price of two different gifts that does not exceed .