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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <vector>
#include <set>


void print_maxy(const std::vector<std::vector<uint64_t>> &maxy, uint64_t N)
{
	for (uint64_t i = 0; i < N; ++i)
	{
		for (uint64_t j = 0; j < N; ++j)
		{
			std::cout << maxy[i][j] << " ";
		}

		std::cout << std::endl;
	}
}


uint64_t get_max_for_day(uint64_t N, uint64_t day, const std::vector<std::vector<uint64_t>> &maxy)
{
	std::set<uint64_t> used;
	uint64_t result = 0;

	do
	{
		--day;

		uint64_t max = 0;
		uint64_t max_index = 0;

		for (uint64_t i = 0; i < N; ++i)
		{
			if (used.find(i) != used.end()) { continue; }

			if (maxy[i][day] > max) {
				max = maxy[i][day];
				max_index = i;
			}
		}

		// DEBUG
//		std::cout << "max: " << max << " " << max_index << std::endl;

		result += max;
		used.insert(max_index);

	} while (day != 0);

	return result;
}


int main()
{
	std::ios_base::sync_with_stdio(0);

	//
	uint64_t N = 0;
	std::cin >> N;

	std::vector<std::pair<uint64_t, uint64_t>> grzyby(N);

	for (uint64_t i = 0; i < N; ++i)
	{
		uint64_t a;
		uint64_t b;

		std::cin >> a;
		std::cin >> b;

		grzyby[i] = std::make_pair(a, b);
	}

	//
	std::vector<std::vector<uint64_t>> maxy(N);  // polana -> dzień -> wartość

	for (uint64_t i = 0; i < N; ++i)
	{
		for (uint64_t j = 0; j < N; ++j)
		{
			maxy[i].push_back(j * grzyby[i].first + grzyby[i].second);
		}
	}

	// DEBUG
//	print_maxy(maxy, N);

	//
	for (size_t i = 1; i < N + 1; ++i)
	{
		std::cout << get_max_for_day(N, i, maxy) << std::endl;
	}

	return 0;
}