#K36817. Maximize Book Count under Weight Constraint

    ID: 25839 Type: Default 1000ms 256MiB

Maximize Book Count under Weight Constraint

Maximize Book Count under Weight Constraint

You are given a shelf with a limited weight capacity \(W\) and \(n\) books. Each book is described by two integers: its thickness and its weight. Your task is to select a set of books such that the total weight does not exceed \(W\), while the number of books selected is maximized.

The selected books must satisfy the following constraint:

\[ \sum_{i \in S} w_i \le W \]

where \(S\) is the set of chosen books and \(w_i\) is the weight of the \(i^{th}\) book.

Note: Although each book has a thickness associated with it, only the weight is relevant in making your selection.

Read input from standard input and output your answer to standard output.

inputFormat

The first line contains two space-separated integers \(n\) and \(W\), where \(n\) represents the number of books and \(W\) the maximum weight capacity of the shelf. This is followed by \(n\) lines, each containing two space-separated integers representing the thickness and weight of a book.

outputFormat

Output a single integer representing the maximum number of books that can be placed on the shelf without exceeding the weight capacity.

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