#K61487. Minimum Boxes

    ID: 31320 Type: Default 1000ms 256MiB

Minimum Boxes

Minimum Boxes

You are given n bottles with specified volumes and an unlimited number of boxes. Each box can hold bottles with a total volume not exceeding a given capacity C. Your task is to determine the minimum number of boxes required to pack all the bottles. Note that a bottle cannot be split between boxes.

The problem can be formulated as finding the minimal number of groups such that the sum of the volumes in each group does not exceed \( C \). This is similar to a bin packing problem where a greedy strategy is acceptable under the provided constraints.

inputFormat

The input consists of three lines:

  1. The first line contains a single integer ( n ) representing the number of bottles.
  2. The second line contains ( n ) space-separated integers representing the volumes of the bottles.
  3. The third line contains a single integer representing the maximum capacity ( C ) of each box.

outputFormat

Output a single integer representing the minimum number of boxes required to pack all the bottles.## sample

5
1 2 3 4 5
5
3