Problem:
Score : 100 points

Problem Statement

There are N items, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.

Taro has decided to choose some of the N items and carry them home in a knapsack.
The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.

Find the maximum possible sum of the values of items that Taro takes home.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq W \leq 10^9

1 \leq w_i \leq W

1 \leq v_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N W
w_1 v_1
w_2 v_2
:
w_N v_N

Output

Print the maximum possible sum of the values of items that Taro takes home.

Sample Input 1

3 8
3 30
4 50
5 60

Sample Output 1

90

Items 1 and 3 should be taken.
Then, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.

Sample Input 2

1 1000000000
1000000000 10

Sample Output 2

10

Sample Input 3

6 15
6 5
5 6
6 4
6 6
3 5
7 2

Sample Output 3

17

Items 2, 4 and 5 should be taken.
Then, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.

Solution in LuaJIT (2.0.4) (judge verdict: Accepted)

local mma, mmi = math.max, math.min
local mfl, mce = math.floor, math.ceil
local function comp(a, b)
  return a < b
end
local function upper_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[1]) then return 1 end
  if not comp(x, ary[num]) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid]) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, W = io.read("*n", "*n")
local v, w = {}, {}
local low_w = true
for i = 1, n do
  w[i], v[i] = io.read("*n", "*n")
end

local function solve_low_w()
  local t = {}
  for i = 1, W do t[i] = 0 end
  for i = 1, n do
    for j = W - w[i], 1, -1 do
      if 0 < t[j] then
        t[j + w[i]] = mma(t[j + w[i]], t[j] + v[i])
      end
    end
    t[w[i]] = mma(t[w[i]], v[i])
  end
  local ret = 0
  for i = 1, W do ret = mma(ret, t[i]) end
  return ret
end

local function solve_low_v()
  local t = {}
  for i = 1, 200000 do t[i] = 0 end
  local v_cursum = 0
  for i = 1, n do
    local vlim = mmi(v_cursum, 200000 - v[i])
    for j = vlim, 1, -1 do
      if 0 < t[j] then
        if t[j + v[i]] == 0 then
          t[j + v[i]] = t[j] + w[i]
        else
          t[j + v[i]] = mmi(t[j + v[i]], t[j] + w[i])
        end
      end
    end
    if t[v[i]] == 0 then
      t[v[i]] = w[i]
    else
      t[v[i]] = mmi(t[v[i]], w[i])
    end
    v_cursum = v_cursum + v[i]
  end
  local ret = 0
  for i = 200000, 1, -1 do
    if 0 < t[i] and t[i] <= W then ret = i break end
  end
  return ret
end
print(solve_low_v())