#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, W; cin >> N >> W; vector dp(W+1), ep(W+1); for( int i = 0; i < N; i++ ) { int w, v; cin >> w >> v; for( int j = 0; j <= W; j++ ) { ep[j] = max(ep[j], dp[j]); if( 0 <= j-w ) { ep[j] = max(ep[j], dp[j-w]+v); } } for( int j = 1; j <= W; j++ ) { ep[j] = max(ep[j], ep[j-1]); } swap(dp, ep); fill(ep.begin(), ep.end(), 0); } for( int X = 1; X <= W; X++ ) { int l = 0, r = 100000000, m; while( l < r-1 ) { m = (l+r)>>1; if( dp[W-X]+m > dp[W] ) { r = m; }else { l = m; } } cout << r << endl; } }