// TLE Θ(N^3) 後ろからやって状態数削減、遷移は高速化せず #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include constexpr int64_t inf = std::numeric_limits::max() / 2; template int64_t measure_exec_time_ms(Fun&& f, bool out = true) { auto start = std::chrono::system_clock::now(); f(); auto elapsed = std::chrono::duration_cast(std::chrono::system_clock::now() - start).count(); if (out) { std::cerr << "solved in " << elapsed << " ms" << std::endl; } return elapsed; } int main() { measure_exec_time_ms( [] { int n; std::cin >> n; std::vector c(n + 1); std::vector v(n + 1); for (int i = 1; i <= n; ++i) { std::cin >> c[i] >> v[i]; } std::vector dp(n + 1, std::vector(n + 1, -inf)); dp[0][0] = 0; for (uint32_t i = n; i > 0; --i) { const uint32_t max_num = std::min(uint32_t(n), uint32_t(n) / i); // dp[num][sum] = max{ pd[num-p][sum-p*i]+p*v[i] | 0<=p<=c[i] } ⋃ {-∞} for (uint32_t num = max_num; num > 0; --num) { const uint32_t pmax = std::min(uint32_t(c[i]), num); for (uint32_t sum = n; sum >= num * i; --sum) { for (uint32_t p = 0; p <= pmax; ++p) { dp[num][sum] = std::max(dp[num][sum], dp[num - p][sum - p * i] + p * v[i]); } } } } for (int32_t k = 1; k <= n; ++k) { std::cout << *std::max_element(dp[k].begin(), dp[k].end()) << '\n'; } } ); return 0; }