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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mt make_tuple
#define ll long long
#define eb emplace_back
#define fi first
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define min(a,b) (a>b?b:a) 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) 
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
#define PI 3.1415926535897932384626
 
using namespace std;
 using namespace __gnu_pbds;
 template <typename T>
 using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 
//----------------------------------------------------------------------------------------------------------------------
 
#define MOD 1000000007 
  
void swap(char &a, char & b){
    char temp = a;
    a = b;
    b = temp;
 
}
 
const ll md = 1e9 + 7;
const int MAXN = 2*1e5 + 50;
 
char str[MAXN];


ll count (string &s,int n){

    int right = n-1;
    vector< int > arr (n+1);
    for(int i = 0;i < n;i++){
        arr[i] = arr[i-1];
        if(s[i] == '(') arr[i]--;
        else arr[i]++;
    }
    ll cnt = 0;
    int op = 0;
    stack< char > st;
    st.push(s[right]);
    right--;
    while(right >= 0){
        char curr = s[right];
        if(st.size() == 0 || st.top() == curr){
            st.push(curr);
        }else{
            st.pop();
        }
        if(st.size() == 0){
            cnt++;
        }
        right--;
    }
    return cnt;
}

    // int n;
    // cin >> n;
    // string s;
    // cin >> s;

    // ll ans = 0;
    // //cout << "rame" << endl;
    // ll ansL = 0;
    // ll ansR = 0;
    // for(int i = 0;i < n;i++){
    //     for( int j = i + 1; j < n;j++){
    //         swap(s[i],s[j]);
    //         ll curr = count(s,n);
    //         if(curr > ans){
    //             ansL = i + 1;
    //             ansR = j + 1;
    //         }
    //         ans = max(ans,curr);
    //         swap(s[i],s[j]);
    //     }
    // }

    // cout << ans << endl;
    // cout << ansL << " " << ansR << endl;

ll inf = 1e18*1LL;

int main(){
    int n,w;
    cin >> n >> w;
    ll sum = 0;
    vector< ll > val (n);
    vector< ll > wgh (n);
    for(int i = 0;i < n;i++){
        cin >> wgh[i] >> val[i];
        sum+=val[i];
    }
    vector< ll > dp (sum + 1, inf);
    dp[0] = 0;
    
    for(int i = 0;i < n;i++){
        for(int j = sum; j >= 0;j--){
            if(dp[j] + wgh[i] <= w){
                dp[j + val[i]] = min(dp[j + val[i]],dp[j] + wgh[i]);
            }
        }
    }
    
    for(int i = sum; i >= 0;i--){
        if(dp[i] != inf){
            cout << i << endl;
            return 0;
        }
    }

    
    return 0;
}