Problem list
Log in
#coci00223 · COCI 2011/2012 Contest 6

Jack

Bronze II 1.0 s 32 MB

In “Blackjack”, a popular card game, the goal is to have cards which sum up to largest number not exceeding 21. Mirko came up with his own version of this game. In Mirko‟s game, cards have positive integers written on them. The player is given a set of cards and an integer M. He must choose three cards from this set so that their sum comes as close as possible to M without exceeding it. This is not always easy since there can be a hundred of cards in the given set. Help Mirko by writing a program that finds the best possible outcome of given game.

Input

The first line of input contains an integer N ($3 \le N \le 100$), the number of cards, and M ($10 \le M$ ≤ 300 000), the number that we must not exceed. The following line contains numbers written on Mirko‟s cards: N distinct space-separated positive integers less than 100 000. There will always exist some three cards whose sum is not greater than M.

Output

The first and only line of output should contain the largest possible sum we can obtain.

Example 1

Input
5 21
5 6 7 8 9
Output
21

Example 2

Input
10 500
93 181 245 214 315 36 185 138 216 295
Output
497
Source
COCI 2011/2012 Contest 6
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code