#K63287. Truck Loading Optimization

    ID: 31720 Type: Default 1000ms 256MiB

Truck Loading Optimization

Truck Loading Optimization

A transport company needs to optimize the loading process of its trucks. Each truck has a fixed loading capacity \( C \) and there are \( n \) items available, each with a specific weight. Your task is to determine the maximum total weight of items that can be loaded onto the truck without exceeding its capacity.

In other words, you are given a list of items with their weights, and you need to choose a subset whose total weight is as high as possible but does not exceed \( C \). This is a typical 0/1 knapsack problem where each item can either be taken or left.

Input Constraints:

  • \( 0 \leq n \leq 100 \)
  • \( 1 \leq C \leq 10^5 \)
  • Each weight is an integer in the range \( [1, 10^4] \)

If no items are available or if all items exceed the capacity, the answer should be 0.

inputFormat

The first line contains two integers \( n \) and \( C \), representing the number of items and the truck's capacity, respectively. The second line contains \( n \) space-separated integers, each representing the weight of an item. If \( n = 0 \), the second line will be empty.

outputFormat

Output a single integer, which is the maximum total weight of items that can be loaded onto the truck without exceeding the capacity.

## sample
5 10
1 4 5 7 3
10