#C1526. Minimum Number of Cars

    ID: 44741 Type: Default 1000ms 256MiB

Minimum Number of Cars

Minimum Number of Cars

You are given n luggage items and a car with a maximum weight capacity m. Each luggage item has a positive integer weight. Your task is to determine the minimum number of cars required to transport all the luggage items under the constraint that the total weight of the luggage assigned to any car does not exceed m. Formally, if a car carries a subset S of items with weights w_i, then it must satisfy:

\( \sum_{i\in S} w_i \le m \)

You can assume that each luggage item must be loaded into some car. This problem is a variant of the bin packing problem and can be approached using greedy algorithms.

inputFormat

The input is given in the following format from standard input (stdin):

  • The first line contains two integers n and m, where n is the number of luggage items and m is the maximum capacity of each car.
  • The second line contains n space-separated integers representing the weights of the luggage items.

outputFormat

Output a single integer to standard output (stdout) denoting the minimum number of cars required to transport all luggage items.

## sample
5 10
2 3 5 7 1
2

</p>