#P10240. Item Transfer Batches

    ID: 12238 Type: Default 1000ms 256MiB

Item Transfer Batches

Item Transfer Batches

There are (n) items numbered from (1) to (n), where the weight of item (i) is (a_i), a positive integer. You have one box that can carry a maximum total weight of (m) (a positive integer). The items are moved in several batches. In each batch, you choose a subset of the remaining items according to the following strategy:

  1. Among all subsets whose total weight does not exceed (m), choose one that contains the maximum number of items.
  2. If there are multiple such subsets, sort the item numbers of each subset in increasing order and choose the subset whose sorted sequence is lexicographically largest (that is, if you compare the sequences element‐by‐element, the first difference has the larger number in the chosen subset).

Your task is to determine how many batches will be needed to move all items following this strategy.

inputFormat

The first line contains two integers (n) and (m) separated by a space. The second line contains (n) positive integers (a_1, a_2, \ldots, a_n) representing the weights of the items.

outputFormat

Output a single integer — the number of batches required to move all items following the given strategy.

sample

4 7
1 2 3 4
2

</p>