Problem list
Log in
#r03201 · Online Judge > GoldOJ

Open the Treasure Chest

Bronze II 2.0 s 256 MB

From $N$ cards, choose exactly three whose values sum to as large a total as possible without exceeding $M$. A valid triple is guaranteed to exist. Print that maximum sum.

Input

Line 1: $N$ and $M$ ($3 \le N \le 100$, $10 \le M \le 300000$). Line 2: $N$ positive integers, each $\le 100000$.

Output

Print the largest achievable three-card sum not exceeding $M$.

Example 1

Input
6 31
4 7 9 11 13 15
Output
31

Example 2

Input
8 250
45 78 112 56 89 23 94 67
Output
250
Source
Online Judge > GoldOJ
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