#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; using vi = vector; using vvi = vector; using vvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vmi = vector; using vvmi = vector; using vvvmi = vector; #define all(a) (a).begin(), (a).end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) void solve(){ } using p = pair; int main(){ ll n, w; cin >> n >> w; vector

vp(n); rep(i, n){ ll a, b; cin >> a >> b; vp[i] = {a, b}; } sort(all(vp), [](const p a, const p b){ if(a.first*b.second != a.second*b.first){ return a.first*b.second > a.second*b.first; }else{ return a.second < b.second; } }); ll nw = w; ll ans = 0; if(w > 1000000){ auto [a, b] = vp[0]; ll c = (nw-1000000)/b; ans += a*c; nw -= b*c; } vvll dp(n, vll(nw+1, -1)); for(int j = 0; j*vp[0].second <= nw; j++)dp[0][j*vp[0].second] = vp[0].first * j; rep2(i, 1, n){ auto [a, b] = vp[i]; rep(j, nw+1){ if(dp[i-1][j] != -1)dp[i][j] = dp[i-1][j]; if(j - b >= 0){ if(dp[i][j-b] != -1)dp[i][j] = max(dp[i][j], dp[i][j-b] + a); } } } ll tmp = 0; rep(i, nw+1)tmp = max(tmp, dp[n-1][i]); cout << ans+tmp << endl; return 0; }