#include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(i=0; i=a; --i) #define in(a) cin >> a #define out(a,b) cout << a << b #define print_vec(v) for(auto it=v.begin();it!=v.end();++it)cout<<*it <<" ";cout<>v[i] #define vpairin(v) for(int i=0;i>a>>b;v[i]=make_pair(a,b);} using namespace std; using lint = long long; int main(void){ int i, j; lint k, cnt=0, x, y; lint p, q, n, m; string s; in(n);in(m); vector > v(n); vpairin(v); vector > v2(n+1, vector (m+1)); rep(i,n+1){ rep(j,m+1){ if(i==0||j==0) v2[i][j]=0; else{ if(j-v[i-1].first>=0){ v2[i][j]=max(v2[i-1][j-v[i-1].first]+v[i-1].second, v2[i-1][j]); } else v2[i][j]=v2[i-1][j]; } } } out(v2[n][m],endl); return 0; }