#C1270. Maximum Combined Weight
Maximum Combined Weight
Maximum Combined Weight
You are given a set of boxes with weights and a weight limit . Your task is to select a subset of these boxes such that the total weight does not exceed , and the combined weight is maximized. In other words, find a subset 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 and , separated by a space. The second line contains integers representing the weights of the boxes.
Output Format:
Output a single integer denoting the maximum combined weight that does not exceed .
inputFormat
The input is read from standard input (stdin). It consists of two lines. The first line contains two integers and , where is the number of boxes and is the weight limit for the conveyor system. The second line contains 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 .## sample
5 20
4 8 5 3 7
20
</p>