#C7571. Minimum Delivery Trips

    ID: 51457 Type: Default 1000ms 256MiB

Minimum Delivery Trips

Minimum Delivery Trips

You are tasked with planning delivery trips for a set of packages using a truck that has a weight limit. For each test case, you are given two integers: N, the number of packages, and W, the weight limit of the truck. You are also provided with a list of N integers representing the weights of these packages.

In each trip, you may deliver a subset of packages provided that the total weight of the selected packages does not exceed W. Your goal is to minimize the number of trips required to deliver all packages.

The problem can be formalized as follows:

$$ \text{Given } N,\; W, \; \text{and weights }\{w_1,w_2,\ldots,w_N\}\text{, find the minimum number of trips } T \text{ such that in each trip } \sum_{i \in S} w_i \le W. $$

Apply an appropriate greedy strategy to achieve the optimal solution.

inputFormat

The first line contains a single integer T, the number of test cases. Each test case is described in the following two lines:

  1. The first line contains two space-separated integers: N (the number of packages) and W (the maximum weight capacity of the truck).
  2. The second line contains N space-separated integers representing the weights of the packages.

outputFormat

For each test case, output a single line containing the minimum number of trips required to deliver all packages.

## sample
2
4 10
2 3 5 7
5 15
1 2 3 4 5
2

1

</p>