#K68537. Minimum Number of Shelves

    ID: 32886 Type: Default 1000ms 256MiB

Minimum Number of Shelves

Minimum Number of Shelves

You are given several test cases. In each test case you are given N books with individual weights and a shelf capacity W. Your task is to determine the minimum number of shelves required to store all the books. Each shelf can only hold books so that the total weight does not exceed \(W\).

Algorithm Description:

  • For each test case, sort the book weights in non-increasing order.
  • Then, repeatedly try to place as many of the lightest remaining books as possible onto the current shelf until no more books can be placed without exceeding \(W\).
  • Count each shelf used and repeat until all books are placed.

Note: If there are no books (i.e. \(N = 0\)), the answer is 0.

inputFormat

The first line contains an integer T representing the number of test cases. Each test case is described as follows:

  • The first line of each test case contains two integers: N (the number of books) and W (the maximum weight capacity of one shelf).
  • If N > 0, the next line contains N space-separated integers representing the weights of the books.

outputFormat

For each test case, output a single line containing one integer which is the minimum number of shelves required.

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

1

</p>