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 C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.Linq;

// AtCoder Educational DP -D Knapsack 1

// N-1個分を、重量Xで持つときの最大値を盛っておけばよい。
// とどのつまり、ans[N][K]は、MAX(ans[N-1][K], ans[N-1][K-treasure[N].weight] + treasure[N].value)である。
// これはすなわち、今回の品物をピックした場合の最大値（＝今回の品物+その重量を引いた重量でのN-1個の最大値）
// と、今回の品物をピックしない場合の最大値（＝今の重量でのN-1の最大値）のどちらか大きいほうということ。


public class Program{

	public static void Main(){
	
		
		
		var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
		var N = input[0];
		var W = input[1];
		
		var list = new List<Prize>();
		
		var dp = new long[N+1,W+1];
		
		for(int i = 0; i < N; i++){
			list.Add(new Prize(Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse)));
			dp[i,0] = 0;
		}
		
		for(int i = 0; i < W; i++){
			dp[0,W] = 0;
		}
		
		for(int NL = 1; NL <= N; NL++){
		
			for(int WL = 1; WL <= W; WL++){
			
				if(WL >= list[NL-1].weight){
					dp[NL,WL] = Math.Max(dp[NL-1,WL], list[NL-1].value + dp[NL-1, WL-list[NL-1].weight]);
				}else{
					dp[NL,WL] = dp[NL-1, WL];
				}
			
			}
		
		
		}
		
		Console.WriteLine(dp[N,W]);
	
	
	}
	
	
	class Prize{
	
		public long weight{get;set;}
		public long value{get;set;}
		
		public Prize(long[] input){
		
			this.weight = input[0];
			this.value = input[1];
		}
	
	
	}




}