#C5278. Optimizing Truck Loading

    ID: 48909 Type: Default 1000ms 256MiB

Optimizing Truck Loading

Optimizing Truck Loading

A warehouse manager is tasked with loading boxes onto trucks while ensuring that the total weight of boxes loaded onto a truck does not exceed its capacity. Given the number of boxes and the weight of each box, along with the maximum capacity for each truck, determine the minimum number of trucks needed.

Formally, for a given truck capacity \(C\) and a list of box weights \(W = [w_1, w_2, \dots, w_n]\), partition \(W\) into the fewest subsets such that for each subset \(S\), the condition \(\sum_{w \in S} w \leq C\) holds.

inputFormat

The input begins with a single integer \(T\) representing the number of test cases. Each test case is described as follows:

  • The first line contains two integers \(N\) and \(C\), where \(N\) is the number of boxes and \(C\) is the maximum capacity of each truck.
  • The second line contains \(N\) space-separated integers, each representing the weight of a box.

outputFormat

For each test case, print a single line containing one integer — the minimum number of trucks required to load all the boxes without exceeding the capacity of any truck.

## sample
2
5 10
1 2 3 4 5
3 8
2 3 6
2

2

</p>