TSSPC Contest 1 P2 - Trick or Treat

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

It's almost Halloween! Adam has devised a plan to get the most out of trick or treating. However, he wants to make sure his plan works correctly, so he has asked you to make a program to check how much value he gets out of trick or treating.

Given N candies, each candy with a value v_i, he wants you to organize his bag so that he can get the greatest value!

Of course, each candy takes one unit of space, and in total he has S units of space in his bag! He cannot always fit all the candies in his bag, so he will have to sometimes take candies out!

Input Specification

The first line will contain the integers N and S. (1 \le S \le N \le 10\,000)

The following N lines will contain the value of each candy.

Output Specification

On a single line, output the maximal value he can fit in his bag.

Sample Input

5 4
8
10
123
1
999

Sample Output

1140

Comments

There are no comments at the moment.