#K4191. Maximum Package Weight Problem

    ID: 26970 Type: Default 1000ms 256MiB

Maximum Package Weight Problem

Maximum Package Weight Problem

You are given a set of packages, each with a specific weight. Your task is to determine the maximum possible weight that can be accumulated by selecting a subset of these packages such that the total weight does not exceed a given limit $W$. This is similar to a knapsack problem where you want to maximize the weight without going over the limit.

Input Format:

  • The first line contains two space-separated integers: n (the number of packages) and $W$ (the maximum allowed weight).
  • The second line contains n space-separated integers representing the weights of the packages.

Output Format:

  • Output a single integer, the maximum total weight obtainable without exceeding $W$.

Constraints: It is guaranteed that the number of packages n is relatively small, so an exhaustive search solution is acceptable for this problem.

Examples:

Input:
5 10
2 3 7 4 6
Output:
10

Input: 4 15 5 5 5 5 Output: 15

</p>

inputFormat

The input is read from standard input (stdin). It consists of two lines:

  • The first line contains two space-separated integers: n (the number of packages) and $W$ (the maximum allowed weight).
  • The second line contains n space-separated integers, where each integer represents the weight of a package.

outputFormat

Output a single integer to standard output (stdout) which is the maximum total weight of the selected subset of packages that does not exceed $W$.

## sample
5 10
2 3 7 4 6
10