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
53
#include<string>
#include<stdio.h>
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<queue>
#include<bitset>
#define ll long long
#define pb push_back
#define sc scanf
#define pr printf
#define f first
#define s second
#define mp make_pair
#define lb lower_bound

using namespace std;

const int ma=1000001;

ll t[ma],t2[ma],w[ma];
pair<ll,ll>pa[ma];

ll ko(int x,int y){
    return ((ll)(x))*pa[y].f+pa[y].s;
}

int main (){
    int n;
    sc("%d",&n);
    for(int i=0;i<n;i++)sc("%lld%lld",&pa[i].f,&pa[i].s);
    sort(pa,pa+n);
    for(int i=0;i<n;i++){
        t[i]=pa[i].s;
        w[0]=max(w[0],t[i]);
    }
    /*for(int i=1;i<n;i++){
        t[i][i]=t[i-1][i-1]+ko(i,i);
        w[i]=t[i][i];
    }*/
    for(int i=1;i<n;i++){
        t2[i]=t[i-1]+ko(i,i);
        w[i]=t2[i];
        for(int j=i+1;j<n;j++){
            t2[j]=ko(i,j)+max(t[j-1],t2[j-1]-ko(i,j-1));
            w[i]=max(w[i],t2[j]);
        }
        swap(t,t2);
    }
    for(int i=0;i<n;i++)pr("%lld\n",w[i]);
    return 0;
}