403205: GYM101064 L The Knapsack problem

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. The Knapsack problemtime limit per test1.0 smemory limit per test256 megabytesinputstandard inputoutputstandard output

To prepare for the ICPC World Finals 2017, your team attended to a training camp. Glauber "the drinker" Sokolov was the teacher, and all teams had to answer a form so he would know what topics were the best to teach. The first day was introductory and Glauber said he would just go over well-known topics. He said "I noticed you all answered that you knew the Knapsack problem very well, so here is a simple exercise about it, follows directly from the definitions. Solve the knapsack problem with repetitions.".

More formally, given N types of items, each one with a weight and a cost, choose some items such that the sum of its weights does not exceed S, and the sum of costs is maximum. You may choose any number of items of each type.

Solve Glauber's exercise.

Input

On the first line two integers N and S, the number of types of items and the maximum allowed weight.

Each of the next N lines has two integers wi and ci, the weight and the cost of the ith type of item.

Limits

  • 1 ≤ N, wi ≤ 103
  • 0 ≤ S, ci ≤ 109
Output

Print a single integer, the cost of the items you choose.

ExampleInput
3 100
14 5
13 2
5 1
Output
35

Source/Category

加入题单

算法标签: