// TLE Θ(N^3) #include #include #include #include constexpr int64_t inf = std::numeric_limits::max() / 2; int main() { 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; }