1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;

typedef long long ll;

int n;
pair<ll, ll> a[N];
ll f[N];

void brute() {
    fill(f, f + n + 1, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = n; j >= 1; --j) {
            f[j] = max(f[j], a[i].first * (j - 1) + a[i].second + f[j - 1]);
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << f[i] << '\n';
    }
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a, a + n);
    brute();
}

int main() {
    ios::sync_with_stdio(false);

    int z = 1;
    while (z--) solve();
    return 0;
}