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
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector<ll> a,b,ans;
struct day {
	day(ll v,int p) : v(v),p(p){}
	day(){}
	ll v; int p;
  	bool operator() (const day &a, const day& b) const {return a.v>b.v;}
};
multiset<day,day> s;
multiset<day,day>::iterator it,it2;
vector<day> c;

int main() {
	int n;
	cin >> n;
	a.resize(n); b.resize(n); c.resize(n);ans.resize(n);
	for (int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		s.insert(day(b[i],i));
	}
	c[0] = *s.begin();
	ans[0]=c[0].v;
	s.erase(s.begin());
	for (int d=1;d<n;d++) {
		int t=d;
		bool ok;
		do {
			ll vm=-1;
			for(it=s.begin();it!=s.end();it++) {
				ll v = b[it->p]+t*a[it->p];
				if (v>vm) {vm=v;it2=it;}
			}
			ll vc = c[t-1].v+a[c[t-1].p];
			//cout << vm << " " << vc << endl;
			if (vm>=vc) {
				ok=true;
				c[t] = *it2;
				c[t].v = vm;
				//cout << it2->p << endl;
				s.erase(it2);
			} else {
				ok=false;
				c[t]=c[t-1];
				c[t].v=vc;
				t--;
				if (t==0) {
					ok = true;
					c[0] = *s.begin();
					s.erase(s.begin());
				}
			}
		} while (!ok);
		for (int i=0;i<=d;i++)
			ans[d]+=c[i].v;
	}
	for (int i=0;i<n;i++)
		cout << ans[i] << endl;
	return 0;
}