atcoder#ABC184F. [ABC184F] Programming Contest
[ABC184F] Programming Contest
Score : points
Problem Statement
Takahashi will participate in a programming contest, which lasts for minutes and presents problems. With his extrasensory perception, he already knows that it will take minutes to solve the -th problem. He will choose zero or more problems to solve from the problems so that it takes him no longer than minutes in total to solve them. Find the longest possible time it takes him to solve his choice of problems.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
5 17
2 3 5 7 11
17
If he chooses the -st, -nd, -rd, and -th problems, it takes him minutes in total to solve them, which is the longest possible time not exceeding minutes.
6 100
1 2 7 5 8 10
33
It is optimal to solve all the problems.
6 100
101 102 103 104 105 106
0
He cannot solve any of the problems.
7 273599681
6706927 91566569 89131517 71069699 75200339 98298649 92857057
273555143
If he chooses the -nd, -rd, and -th problems, it takes him minutes in total to solve them.