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++ (GCC 9.2.1) (judge verdict: Runtime Error)

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<tuple>
#include<map>
#include <numeric>

using namespace std;
#define etm cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define pii pair<int , int>
#define pdd pair<double , double>
#define pll pair<ll,ll>
#define vpl vector<pll>
#define vll vector<ll>
#define vb vector<bool>
#define vvbb vector<vb>
#define vs vector<string>
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)

#define fo(i,start,end) for(ll i=start;start<end?i<end:i>end;start<end?i+=1:i-=1)
#define MOD 1000000007
#define ld long double
#define inf 1e18
#define mp  make_pair
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vector<pair<ll,ll>>>
#define vvll vector<vector<ll>>
#define all(x) x.begin(),x.end()
#define allb(x) x.rbegin(),x.rend()
#define fi first
#define se second
#define test ll T;cin>>T;while(T--)
#define show(w,size) for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define umll unordered_map<ll,ll>
#define mll   map<ll,ll>
#define countbit __builtin_popcount // Number of set bits .
#define in insert
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd(ll a,ll b){if(a<b)return gcd(b,a);else if(b==0)return a;else return gcd(b,a%b);}
ll isPrime(ll n){ll p=(ll)sqrt(n);fo(i,2,p+1) if(n%i==0) return 0;return 1;}// return 1 if prime
ll pow(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll pow_m(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m) { return pow_m(a, m-2, m);}
ll max(ll a,ll b){if(a>=b)return a;else return b;}
ll min(ll a,ll b){if(a<=b)return a;else return b;}
/*
const ll N=1000;
ll n,m,x,y;
char g[N+1][N+1];
ll b[N+5],w[N+5];
ll dp[N+5][2];

int main(){
    fastio;
    cin>>n>>m>>x>>y;
    fo(i,0,n){
        fo(j,0,m){
            cin>>g[i][j];
        }
    }
    fo(i,0,m){
        fo(j,0,n){
            if(g[j][i]=='.')w[i+1]++;
            else b[i+1]++;
        }
    }
    fo(i,1,m+1){
        b[i]+=b[i-1];
        w[i]+=w[i-1];
    }
    fo(i,1,m+1)dp[i][0]=dp[i][1]=1e9;
    fo(i,1,m+1){
        fo(j,x,y+1){
            ll r=i;
            ll l=i-j+1ll;
            if(l<1)continue;
            dp[i][0]=min(dp[i][0],b[r]-b[l-1]+dp[l-1][1]);
            dp[i][1]=min(dp[i][1],w[r]-w[l-1]+dp[l-1][0]);
        }
    }
    cout<<min(dp[m][0],dp[m][1])<<endl;
    return 0;
}

*/
/*
void solve() {
    ll n;
    cin>>n;
    vll v(n),dp(n+1,0);
    fo(i,0,n){
        cin>>v[i];
        dp[v[i]]=i;
    }
    string ans="1";
    ll l=dp[1],r=dp[1];
    fo(i,2,n+1){
        if(dp[i]==l-1&&r-dp[i]+1==i){
            l--;
            ans+="1";
        }
        else if(dp[i]==r+1&&dp[i]-l+1==i){
            r++;
            ans+="1";
        }
        else if(dp[i]>=l&&dp[i]<=r&&r-l+1==i){
            ans+="1";
        }
        else{
            ans+="0";
            l=min(l,dp[i]);
            r=max(r,dp[i]);
        }
    }
    cout<<ans<<endl;
}
*/

/*
int main(){
    fastio;
    ll r,c;
    cin>>r>>c;
    ll ans[r][c],count=2;
    if(r==1&&c==1)cout<<"0"<<endl;
    else if(r==1||c==1){
        if(r==1){
            fo(i,0,c)cout<<i+2<<" ";
            cout<<endl;
        }
        else{
            fo(i,0,r)cout<<i+2<<" ";
            cout<<endl;
        }
    }
    else{
        fo(i,0,c){
            ans[0][i]=count;
            count++;
        }
        fo(i,1,r){
            ll k=count;
            fo(j,0,c){
                ans[i][j]=k*(j+2);
            }
            count++;
        }
        fo(i,0,r){
            fo(j,0,c){
                cout<<ans[i][j]<<" ";
            }
            cout<<endl;
        }
    }
    return 0;
}
 */

/*
int main(){
    fastio;
    ll n,k;
    cin>>n>>k;
    vll v(n);
    fo(i,0,n)cin>>v[i];
    vll dp(n,inf);
    dp[0]=0;
    fo(i,0,n){
        fo(j,i+1,i+k+1){
            if(j<n)dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}
 */

void max_self(ll& a,ll b){
    a=max(a,b);
}

int main(){
    fastio;
    ll n,w;
    cin>>n>>w;
    vll dp(w+1);
    fo(i,0,n){
        ll weight,value;
        cin>>weight>>value;
        ll weight_already=w-weight;
        fo(j,weight_already,-1){
            max_self(dp[weight_already+weight],dp[weight_already]+value);
        }
    }
    ll ans=0;
    fo(i,0,w+1)max_self(ans,dp[i]);
    cout<<ans<<endl;
    return 0;
}