#P6437. [COCI 2011/2012 #6] JACK

[COCI 2011/2012 #6] JACK

Problem Description

Given nn positive integers a1ana_1 \dots a_n, choose 33 numbers such that their sum is not greater than the given integer mm. Find the maximum possible value of this sum.

Input Format

The first line contains two integers, representing the number of integers nn and the given integer mm.

The second line contains nn integers, representing the given numbers aia_i.

Output Format

Output one integer in one line, representing the answer.

5 21
5 6 7 8 9
21
10 500
93 181 245 214 315 36 185 138 216 295

497

Hint

Constraints

  • For 100%100\% of the testdata, it is guaranteed that 1n1001 \leq n \leq 100, 6m3×1056 \leq m \leq 3 \times 10^5, 1ai1051 \leq a_i \leq 10^5, and it is guaranteed that a solution exists.

Notes

This problem is translated from COCI2011-2012 CONTEST #6 T1 JACK. Translation by @一扶苏一.

Translated by ChatGPT 5