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
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>

using namespace std;

const int MAX_N = 1000001;

struct Node {
  long long speed;
  long long start;
  bool done;
};

Node t[MAX_N];
int n;

bool cmp(const Node &i, const Node &j) {
  if(i.speed < j.speed) return true;
  if(i.start < j.start && i.speed == j.speed) return true;
  return false;
}
void solve() {
  long long res = 0;
  long long all_speed = 0;
  sort(t, t+n, cmp);
  //for(int i = 0; i < n; i++) printf("%lld %lld\n", t[i].speed, t[i].start);
  for(int i = 0; i < n; i++) {
    
    int maxi = -1;
	long long max = 0;
	int count = 0;
	long long speed = 0;
	for(int j = 0; j < n; j++) {
	  if(t[j].done) {count++; speed += t[j].speed; continue;}
	  long long diff = count * t[j].speed + t[j].start + (all_speed - speed);
	  if(diff > max || (diff ==max && (maxi==-1 || t[j].speed >= t[maxi].speed))) {
	    maxi = j;
		max = diff;
	  }
	}
	t[maxi].done = true;

    res += max;
	all_speed += t[maxi].speed; 
    printf("%lld\n", res);
  }
}
int main(int args, char* argv[]) {
  scanf("%d", &n);  
  for(int i = 0; i < n; i++) {
    long long a, b;
	scanf("%lld%lld", &a, &b);
    t[i].speed = a;
	t[i].start = b;
  }
  solve();
  return 0;
}