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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef vector<Pll> vpll;
const ll INF = 1ll << 62;
ll C[120000];
ll B[120000];
//bool Ac[120000];
int n;
vpll Polany;
int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		ll a, b;
		scanf("%lld%lld", &a, &b);
		Polany.push_back(Pll(a,b));
	}
	sort(Polany.begin(), Polany.end());
	
	for(int i = 0; i < n; ++i)
	{
		C[i] = Polany[i].first;
		B[i] = Polany[i].second;
		//Ac[i] = true;
	}
	ll sumka = 0;
	for(int i = 0; i < n; ++i)
	{
		int ind = 0;
		ll curmax = -1;
		for(int j = 0; j < n; ++j)
			if(curmax < B[j])
			{
				curmax = B[j];
				ind = j;
			}
		//Ac[ind] = false;
		sumka += B[ind];
		B[ind] = -INF;
		ll c = C[ind];
		for(int i = 0; i < ind; ++i)
			B[i] += c;
		for(int i = ind+1; i < n; ++i)
			B[i] += C[i];;
		
		printf("%lld\n", sumka);
	}
}