PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000483. Cuộc thi lập trình (Programming Contest)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cuộc thi lập trình (Programming Contest)

Programming Contest

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Takahashi enters a programming competition with NN problems, numbered 11 through NN, and a duration of TT minutes. His unusual ability tells him in advance that problem ii requires exactly AiA_i minutes.

He may select any subset of the problems, including the empty subset. Each selected problem is solved once, and their combined solving time must fit within the contest duration.

Find the maximum possible total solving time that is at most TT.

Input

  • The first line contains two integers N,TN,T, the number of problems and contest duration in minutes.
  • The second line contains NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N, the respective solving times in minutes.

Output

Print one integer: the maximum total solving time not exceeding TT. If no problem fits, print 0.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le 20; 1≤T≤10000000001\le T\le 1000000000; 1≤Ai≤1091\le A_i\le 10^9 for every 1≤i≤N1\le i\le N.
  • Subtask 2 (30 points): 1≤N≤401\le N\le 40; 1≤T≤2000001\le T\le 200000; 1≤Ai≤1091\le A_i\le 10^9 for every 1≤i≤N1\le i\le N.
  • Subtask 3 (50 points): 1≤N≤401\le N\le 40; 1≤T≤10000000001\le T\le 1000000000; 1≤Ai≤1091\le A_i\le 10^9 for every 1≤i≤N1\le i\le N.

Examples

Input 1

5 17
2 3 5 7 11

Output 1

17

Explanation 1

Select the first four problems: 2+3+5+7=172+3+5+7=17 minutes. This equals the time limit, so no feasible larger sum exists.

Input 2

6 100
1 2 7 5 8 10

Output 2

33

Explanation 2

All six problems take 1+2+7+5+8+10=331+2+7+5+8+10=33 minutes, below 100. Omitting any problem reduces that total.

Input 3

6 100
101 102 103 104 105 106

Output 3

0

Explanation 3

Even the shortest problem needs 101 minutes, more than 100. Only the empty subset is feasible, with total 0.