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 <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

struct bucket {
	uint64_t beg;
 	uint64_t inc;
};

bool compinc (const bucket & lhs, const bucket  & rhs){
	if(lhs.inc == rhs.inc){
		lhs.beg < rhs.beg;
	}
	return lhs.inc < rhs.inc;
}

std::vector <bucket> ordinc;

uint64_t count (const vector<bucket> &what, int i){
	uint64_t ret = 0;
	for(auto j = 0ull; j < i; j ++){
		ret += what[j].beg + what[j].inc * j;
	}
	return ret;
}
int main(){
	int N;
	cin >>  N;
	for(int a = 0; a < N; a++){
		bucket cur;
		cin >> cur.inc;
		cin >> cur.beg;
		ordinc.push_back(cur);
	}
	sort(ordinc.begin(), ordinc.end(), compinc);
	uint64_t totleft = count(ordinc, ordinc.size());
	vector<uint64_t> ans;
	ans.push_back(totleft);
	for(int d = 1; d < N; d++){
		uint64_t sofar = 0;
		uint64_t min = ordinc[ordinc.size() - 1].beg + ordinc[ordinc.size() - 1].inc * (ordinc.size() - 1); 
		int todel = ordinc.size() - 1;
		for(int i = ordinc.size() - 1; i >= 0; i--){
			auto a = ordinc[i].beg + ordinc[i].inc * i + sofar;
			if (min > a){
				todel = i;
				min = a; 
			}
			sofar += ordinc[i].inc;
		}
		ordinc.erase(ordinc.begin() + todel, ordinc.begin() + todel + 1);
		totleft = totleft - min;
		ans.push_back(totleft);
	}
	for(auto a =  ans.rbegin(); a != ans.rend(); a ++){
		std::cout << *a << std::endl;
	}	
}