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 Java8 (OpenJDK 1.8.0) (judge verdict: Runtime Error)

import java.io.*;
import java.util.*;
import java.math.*;
public class Main {

    InputStream is;
    PrintWriter out;
    
    long mod = (long)(1e9 + 7), inf = (long)(1e18);
   //pair class::sieve::modPower::gcd::lbound
	  
	
	  
    void solve()
    {
		int n=ni();
		int w=ni();
		long dp[][]=new long[n+1][w+1];
		int a[][]=new int[n][2];
		for(int i=0;i<n;i++){
			a[i][0]=ni();
			a[i][1]=ni();
		}
		
		for(int i=1;i<n+1;i++)
		{
			for(int j=1;j<w+1;j++)
			{
				if(j-a[i-1][0]>=0)
				{
					dp[i][j]=Math.max(dp[i-1][j-a[i-1][0]]+a[i-1][1],dp[i-1][j]);
				}
				else
					dp[i][j]=dp[i-1][j];
			}
		}
		//for(int i=0;i<=n;i++)
	//	{
		//	for(int j=0;j<=w;j++)
			//	out.print(dp[i][j]+" ");
				//out.println();
		//}
		out.println(dp[n][w]);
		
	}
	
	
	
	

	
	
	
	
	
	
	
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 static ArrayList<Integer> sieve(int n)
	{
		boolean mark[]=new boolean[n+1];
		mark[0]=mark[1]=true;
		for(int i=2;i<=(int)Math.sqrt(n);i++)
		{
			if(mark[i]==false){
			for(int p=2*i;p<n;p+=i)
			mark[p]=true;}}

		ArrayList<Integer> l=new ArrayList<Integer>();
		int ind=0;
		for(int i=0;i<n+1;i++)
		{
			if(mark[i]==false)
			l.add(i);
		}
		return l;
		
	}
	 
	
	
	   static long gcd(long a, long b) 
	{ 
   		 if (b == 0) 
        	return a; 
    	return gcd(b, a % b);  
	}




	
	static long lbound(LinkedList<Long> l,long ele)
	{
		int low=0;
		int high=l.size()-1;
		int ans=0;
		while(low<high)
		{
			int mid=(low+high)/2;
			if(l.get(mid)==ele)
			{ans=mid;break;}
			else if(l.get(mid)>ele)
			{high=mid-1;}
			else
			{ans=mid;low=mid;}	
		}
		return l.get(ans);
	}
	  
	  
	  
	static long modPower(long x, long y, long p) 
    { 
        long res = 1;      
        x = x % p;  
        while (y > 0) 
        { 
            if((y & 1)==1) 
                res = (res * x) % p; 
            y = y >> 1;  
            x = (x * x) % p;  
        } 
        return res; 
    } 
  
static  class pair
 {
 int key;
 int value;	 	
 public pair(int key,int value)
 {
	 this.key=key;
	 this.value=value;
 }
}

    //---------- I/O Template ----------
    
    public static void main(String[] args) { new Main().run(); }
    void run() { 
        is = System.in; 
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }
    
    byte input[] = new byte[1024];
    int len = 0, ptr = 0;
    
    int readByte() { 
        if(ptr >= len) { ptr = 0; 
            try { len = is.read(input); } 
            catch(IOException e) { throw new InputMismatchException(); } 
            if(len <= 0) { return -1; } 
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() { 
        int b = readByte(); 
        while(b != -1 && isSpaceChar(b)) { b = readByte(); } 
        return b;
    }
    
    char nc() { return (char)skip(); }
    String ns() { 
        int b = skip(); 
        StringBuilder sb = new StringBuilder(); 
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } 
        return sb.toString();
    }
    String nLine() { 
        int b = skip(); 
        StringBuilder sb = new StringBuilder(); 
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } 
        return sb.toString();
    }
    int ni() { 
        int n = 0, b = readByte(); 
        boolean minus = false; 
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } 
        if(b == '-') { minus = true; b = readByte(); } 
        if(b == -1) { return -1; }  //no input 
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } 
        return minus ? -n : n;
    }
    long nl() { 
        long n = 0L;    int b = readByte(); 
        boolean minus = false; 
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } 
        if(b == '-') { minus = true; b = readByte(); } 
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } 
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) { 
        int a[] = new int[n]; 
        for(int i = 0; i < n; i++) { a[i] = ni(); } 
        return a;
    }
    char[] ns(int n) { 
        char c[] = new char[n]; 
        int i, b = skip(); 
        for(i = 0; i < n; i++) { 
            if(isSpaceChar(b)) { break; } 
            c[i] = (char)b; b = readByte(); 
        } return i == n ? c : Arrays.copyOf(c,i);
    }
	
}