#C7614. Minimum Number of Shelves

    ID: 51505 Type: Default 1000ms 256MiB

Minimum Number of Shelves

Minimum Number of Shelves

You are given n books and a shelf with maximum width L. Each book has a given width. The objective is to determine the minimum number of shelves required to store all the books if you are allowed to rearrange them in any order. The solution involves sorting the books in descending order and then greedily placing them on shelves: if the current book fits in the current shelf (i.e. the sum of widths does not exceed L), it is added; otherwise, a new shelf is started. Formally, if the widths are \( w_1, w_2, \dots, w_n \) (possibly reordered), then compute the minimal number of shelves needed such that the sum of the widths on each shelf does not exceed \( L \).

inputFormat

The input consists of two lines:

  1. The first line contains two space-separated integers \( n \) and \( L \), where \( n \) is the number of books and \( L \) is the maximum width allowed for a shelf.
  2. The second line contains \( n \) space-separated integers representing the widths of the books.

outputFormat

Output a single integer representing the minimum number of shelves required.

## sample
5 10
1 2 3 4 5
2