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
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

struct P { LL a, b; };

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<P> D(n);
	vector<LL> X(n);
	
	for(int i = 0; i < n; ++i) {
		cin >> D[i].a >> D[i].b;
	}
	
	sort(D.begin(), D.end(), [](P p1, P p2) { return p1.a < p2.a; });
	
	for (int i = 0; i < n; ++i) {
		X[i] = D[i].b;
	}
	
	LL result = 0;
	for (int s = 0; s < n; ++s) {
		int idx = max_element(X.begin(), X.end()) - X.begin();
		result += X[idx];
		
		for (int j = 0; j < n; ++j) {
			if (idx==j || X[j]==-1) continue;
			if (j < idx)
				X[j] += D[idx].a;
			else
				X[j] += D[j].a;
		}
		X[idx] = -1;
		
		cout << result << endl;
	}
}