#include #define VARNAME(x) #x #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using ld = long double; template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; constexpr ld PI = static_cast(3.1415926535898); template constexpr T INF = numeric_limits::max() / 10; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; ll W; cin >> N >> W; vector v(N); vector w(N); ll wsum = 0; ll psum = 0; for (int i = 0; i < N; i++) { cin >> v[i] >> w[i]; wsum += w[i]; psum += v[i]; } if (wsum <= W) { cout << psum << endl; } else { const ll P = *max_element(v.begin(), v.end()); constexpr ll EPS_INV = 10; const ll K = max(1LL, P / EPS_INV / N); auto V = v; for (int i = 0; i < N; i++) { V[i] /= K; } const ll PMAX = accumulate(V.begin(), V.end(), 0LL); vector> dp(N + 1, vector(PMAX + 1, INF)); //iコ見て価値pで最小重さ vector> prev(N + 1, vector(PMAX + 1, -1)); dp[0][0] = 0; for (ll i = 0; i < N; i++) { for (ll j = 0; j <= PMAX; j++) { if (dp[i][j] == INF) { continue; } if (dp[i + 1][j] > dp[i][j]) { dp[i + 1][j] = dp[i][j]; prev[i + 1][j] = j; } if (dp[i + 1][j + V[i]] > dp[i][j] + w[i]) { dp[i + 1][j + V[i]] = dp[i][j] + w[i]; prev[i + 1][j + V[i]] = j; } } } for (ll j = PMAX - 1; j >= 0; j--) { if (dp[N][j] == INF) { dp[N][j] = dp[N][j + 1]; } } ll maxind = PMAX; for (ll i = PMAX; i >= 0; i--) { if (dp[N][i] <= W) { maxind = i; break; } } ll pos = maxind; ll ans = 0; for (int i = N; i >= 1; i--) { const ll next = prev[i][pos]; if (next < pos) { ans += v[i - 1]; } pos = next; } cout << ans << endl; } return 0; }