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
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
using namespace std;

#define pi pair<int,int>
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define pl pair<long long,long long>
#define pb push_back

struct pol
{
    int a;
    long long b;

    friend bool operator < (pol p1, pol p2)
    {
        return p1.a<p2.a;
    }
};

pol t[1000005];
long long w[1000005];

int main()
{
    int n,i,j;

    scanf ("%d", &n);

    for (i=0; i<n; i++)
        scanf ("%d %lld", &t[i].a, &t[i].b);

    sort(t,t+n);

    for (i=0; i<n; i++)
        for (j=n; j; j--)
            w[j]=max(w[j],w[j-1]+(long long)t[i].a*(j-1)+t[i].b);

    for (i=1; i<=n; i++)
        printf ("%lld\n", w[i]);

    return 0;
}