#C2235. Elevator Trip Optimization

    ID: 45529 Type: Default 1000ms 256MiB

Elevator Trip Optimization

Elevator Trip Optimization

You are given a set of items that need to be transported using an elevator. Each item has a specific weight. The elevator has a maximum load capacity and can carry any combination of items as long as their total weight does not exceed the capacity. Your task is to determine the minimum number of trips required to transport all items.

Note: The items can be loaded in any order on each trip, and the same trip can include several items if the sum of their weights does not exceed the elevator's capacity. The optimal strategy should use the fewest trips possible.

The mathematical formulation of the problem is similar to the bin packing problem, where you want to pack items of weights \(w_1, w_2, \dots, w_T\) into bins (trips) of capacity \(C\). Find the minimum number of such bins required.

inputFormat

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

  • The first line contains two integers separated by a space: \(T\) (the number of items) and \(C\) (the maximum load capacity of the elevator).
  • The second line contains \(T\) integers separated by spaces, representing the weights of the items.

outputFormat

Output to standard output (stdout) a single integer, which is the minimum number of trips required to transport all the items.

## sample
5 200
50 80 120 70 90
3

</p>