#include #include #include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using modint = atcoder::static_modint<998244353>; i64 dp[2501][2501]; int main(){ int N; cin >> N; vector> wWVD; rep(i,N){ i64 w, c, v; w = i+1; cin >> c >> v; c = min(c,N/w); for(i64 d=1; d<=c; d*=2){ wWVD.push_back({w,w*d,v*d,d}); c -= d; if(d&c){ wWVD.push_back({w,w*d,v*d,d}); c -= d; } } } sort(wWVD.rbegin(), wWVD.rend()); rep(i,N+1) rep(j,N+1) dp[i][j] = -INF; rep(i,N+1) dp[0][i] = 0; for(auto [w,W,V,D] : wWVD){ i64 K = N / w; for(i64 k=min(K,N-D+1); k>=D; k--){ for(i64 i=W; i<=N; i++){ dp[k][i] = max(dp[k][i], dp[k-D][i-W] + V); } } } for(int k=1; k<=N; k++) cout << dp[k][N] << '\n'; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;