#K75352. Maximum Subset Sum

    ID: 34400 Type: Default 1000ms 256MiB

Maximum Subset Sum

Maximum Subset Sum

Given a set of (n) integers and an integer (S), the task is to choose a subset of these integers such that the sum of the subset is as large as possible, but does not exceed (S). In other words, you need to maximize (\sum_{i \in I} a_i) subject to (\sum_{i \in I} a_i \le S), where (I) is an index set corresponding to the chosen subset. Note that the empty subset (with sum 0) is always allowed. The input guarantees that (n) is small enough to allow an exhaustive search solution.

inputFormat

The first line contains two integers (n) and (S) separated by a space, where (n) is the number of elements. The second line contains (n) space-separated integers representing the elements of the set.

outputFormat

Output a single integer, which is the maximum sum of any subset of the given numbers that does not exceed (S).## sample

5 10
2 3 5 8 1
10