#C6837. Maximum Strawberry Carry Weight

    ID: 50641 Type: Default 1000ms 256MiB

Maximum Strawberry Carry Weight

Maximum Strawberry Carry Weight

Bob has a collection of strawberries, each with a given weight. He wants to carry as many strawberries as possible without exceeding his carrying capacity (weight limit).

You are given:

  • An integer \(m\) representing the number of strawberries.
  • An integer \(w\) representing the maximum total weight Bob can carry.
  • A list of \(m\) positive integers representing the individual weights of the strawberries.

Your task is to determine the maximum weight Bob can carry by selecting a subset of the strawberries such that the sum of the weights does not exceed \(w\). Formally, if \(S\) is a subset of the given weights, you need to maximize \(\sum_{x \in S} x\) subject to \(\sum_{x \in S} x \le w\).

It is guaranteed that the number of strawberries is small enough to try every combination.

inputFormat

The input is read from stdin and has the following format:

m w
w1 w2 ... wm

Where:

  • \(m\) is the number of strawberries.
  • \(w\) is the maximum total weight Bob can carry.
  • \(w1, w2, \ldots, wm\) are the weights of the strawberries.

outputFormat

The output should be printed to stdout and consists of a single integer representing the maximum weight that Bob can carry without exceeding the limit \(w\).

## sample
5 10
2 3 5 8 6
10

</p>