#C8598. Minimum Truck Trips

    ID: 52597 Type: Default 1000ms 256MiB

Minimum Truck Trips

Minimum Truck Trips

Given a collection of items with specified weights and a truck that can carry a maximum weight W per trip, determine the minimum number of trips needed to transport all the items. In each trip, the truck can carry either one or two items. When carrying two items in one trip, the sum of their weights must not exceed W. Formally, for any two items with weights \(w_i\) and \(w_j\), they can be paired in the same trip if and only if

[ w_i + w_j \leq W ]

If pairing is not possible, the truck carries a single item for that trip. Your task is to compute the minimum number of trips required for each test case.

inputFormat

The input is read from standard input (stdin). The first line contains a single integer T representing the number of test cases. Each test case consists of two lines:

  • The first line contains two integers N and W: the number of items and the maximum weight the truck can carry in one trip.
  • The second line contains N integers representing the weights of the items.

outputFormat

For each test case, output a single integer — the minimum number of trips required to transport all items. Each output should be printed on a new line to standard output (stdout).## sample

2
5 10
1 2 3 4 5
3 5
2 3 5
3

2

</p>