Under construction

Still being built. Things may change

Ordinary Knapsack

Interview

Time limit2sMemory limit512 MB

Summary
Given N items with weights and values, pick a subset with total weight at most K to maximize total value.
Level

Easy3 of 10

Topics
Dynamic programming
Solved
No attempts yet

Problem

Junseo enlists in a month. He wants to take one trip before then, and since he will be away from the world for a while he wants to enjoy the trip as much as he can, so he packs his backpack for the highest possible value.

Junseo has NN items he thinks he needs for the trip. Each item has a weight WW and a value VV, and carrying that item in the backpack lets Junseo enjoy the trip by VV. Junseo has never marched before, so he can only carry a backpack whose packed weight sums to at most KK.

There is only one copy of each item, so the only choice per item is to pack it or leave it. Find the largest total value of the items Junseo can pack.

Input

The first line contains the number of items NN and the weight KK that Junseo can bear. (1≤N≤1001 \le N \le 100, 1≤K≤100,0001 \le K \le 100{,}000)

Each of the next NN lines contains the weight WW and the value VV of one item. (1≤W≤100,0001 \le W \le 100{,}000, 0≤V≤1,0000 \le V \le 1{,}000)

Every number in the input is an integer.

Output

Print the largest total value of the items that can be packed, on one line.

Examples3

  1. Example 1

    Input
    4 7
    6 13
    4 8
    3 6
    5 12
    
    Expected output
    14
    
  2. Example 2

    Input
    3 10
    6 7
    5 5
    5 5
    
    Expected output
    10
    
  3. Example 3

    Input
    1 1
    2 1000
    
    Expected output
    0