#C4749. Maximum Book Value

    ID: 48321 Type: Default 1000ms 256MiB

Maximum Book Value

Maximum Book Value

You are given (N) books, each with a given thickness and value. Your task is to select a subset of these books such that the total thickness does not exceed the limit (L) and the sum of their values is maximized. This is a variant of the 0-1 Knapsack problem. Formally, for a subset (S) of books, you must have [ \sum_{i \in S} t_i \le L ] and you want to maximize [ \sum_{i \in S} v_i].

Each book is characterized by its thickness (t_i) and its value (v_i).

inputFormat

The first line contains two integers (N) and (L) where (N) is the number of books and (L) is the maximum allowed thickness. The following (N) lines each contain two integers: the thickness and the value of a book.

outputFormat

Output a single integer representing the maximum total value of books that can be chosen without exceeding the thickness limit.## sample

4 7
1 4
3 2
4 5
2 3
12