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

using namespace std;

typedef unsigned long long ull;

int main()
{
	int n;
	cin >> n;
	
	vector<pair<ull, ull> > ab(n);
	
	for (int i = 0; i < n; i++)
		cin >> ab[i].first >> ab[i].second;
	
	sort(ab.begin(), ab.end());
	
	vector<ull> dp(n);
	vector<ull> dp2(n);

	for (int k = 0; k < n; k++)
	{
		ull m = k > 0 ? dp[k-1] : 0;
//		cout << "k=" << k << " m=" << m;
	
		for (int i = k; i < n; i++)
		{
			dp2[i] = ab[i].second + k * ab[i].first + m;
//			cout << " " << dp2[i];
			m = max(m, dp[i]);
		}
//		cout << " " << dp2[n-1] << "\n";
		
		if (k > 0)
			cout << m << "\n";

		dp.swap(dp2);
	}
	
	cout << dp[n-1] << "\n";

	return 0;
}