#C1270. Maximum Combined Weight

    ID: 42156 Type: Default 1000ms 256MiB

Maximum Combined Weight

Maximum Combined Weight

You are given a set of NN boxes with weights w1,w2,,wNw_1, w_2, \ldots, w_N and a weight limit WW. Your task is to select a subset of these boxes such that the total weight does not exceed WW, and the combined weight is maximized. In other words, find a subset S{1,2,,N}S \subseteq \{1, 2, \ldots, N\} such that $$\sum_{i \in S} w_i \le W$$ and $$\sum_{i \in S} w_i$$ is as large as possible.

Input Format:
The first line contains two integers NN and WW, separated by a space. The second line contains NN integers representing the weights of the boxes.

Output Format:
Output a single integer denoting the maximum combined weight that does not exceed WW.

inputFormat

The input is read from standard input (stdin). It consists of two lines. The first line contains two integers NN and WW, where NN is the number of boxes and WW is the weight limit for the conveyor system. The second line contains NN space-separated integers representing the weight of each box.

outputFormat

Print a single integer to standard output (stdout), which is the maximum combined weight that does not exceed the weight limit WW.## sample

5 20
4 8 5 3 7
20

</p>