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
#include <iostream>
#include <algorithm>
using namespace std;
long long dyn[2000002], wyn[1000002];
pair<long long, long long> tab[1000002];
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i=0; i<n; i++)
	{
		cin >> tab[i].second >> tab[i].first;
	}
	for (int i=1; i<(1<<n); i++)
	{
		for (int j=0; j<n; j++)
		{
			if ((i&(1<<j))!=0)
			{
				dyn[i]=max(dyn[i], dyn[i-(1<<j)]+tab[j].first+(__builtin_popcount(i)-1)*tab[j].second);
				//cout << dyn[i-(1<<j)] << " " << tab[j].first << " " << (__builtin_popcount(i)-1)*tab[j].second << "\n";
			}
		}
		//cout << i << " " << dyn[i] << "\n";
		wyn[__builtin_popcount(i)]=max(wyn[__builtin_popcount(i)], dyn[i]);
	}
	for (int i=1; i<=n; i++)
	{
		cout << wyn[i] << "\n";
	}
	return 0;
}