#BS0000483. Cuộc thi lập trình (Programming Contest)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 problems, numbered through , and a duration of minutes. His unusual ability tells him in advance that problem requires exactly 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 .
Input
- The first line contains two integers , the number of problems and contest duration in minutes.
- The second line contains integers , the respective solving times in minutes.
Output
Print one integer: the maximum total solving time not exceeding . If no problem fits, print 0.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input 1
5 17
2 3 5 7 11
Output 1
17
Explanation 1
Select the first four problems: 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 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.