#K72012. Minimum Number of Shelves

    ID: 33659 Type: Default 1000ms 256MiB

Minimum Number of Shelves

Minimum Number of Shelves

You are given n books and a shelf with a maximum height limit H. Each book is described by its thickness and height. Although the thickness is provided, it is not used in determining the number of shelves needed.

Your task is to determine the minimum number of shelves required to place all the books such that the sum of the heights of the books on any shelf does not exceed H. A common strategy is to sort the books in descending order by their height and then greedily add books to the current shelf. If adding a book exceeds the height limit, start a new shelf.

The condition for a shelf is mathematically expressed as:

\(\sum_{i \in S} h_i \leq H\),

where \(h_i\) is the height of the ith book on shelf S.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains two integers, n (the number of books) and H (the maximum allowed height per shelf).
  • The next n lines each contain two integers representing the thickness and height of a book, respectively.

Note: The thickness value is provided for each book but not used in the computation.

outputFormat

The output is printed to stdout and is a single integer representing the minimum number of shelves needed to store all the books.

## sample
4 10
5 3
2 5
3 6
1 4
3

</p>