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
#include <bits/stdc++.h>

int MAX[3];
int ile[3];

int odp[100003];
std::vector<int> v;
std::queue<std::pair<int, std::pair<int, int> > > q;
std::map<std::pair<int, std::pair<int, int> > , int> odw;

void przelej(int skad, int dokad) {
	int wart[3] = {v[0], v[1], v[2]};
	int ileDodaje = std::min(MAX[dokad], wart[skad] + wart[dokad]) - wart[dokad];
	wart[dokad] += ileDodaje;
	wart[skad] -= ileDodaje;
	if (odw.count({wart[0], {wart[1], wart[2]}}) == 0) {
		odw[{wart[0], {wart[1], wart[2]}}] = odw[{v[0], {v[1], v[2]}}] + 1;
		q.push({wart[0], {wart[1], wart[2]}});
	}
}

int main() {
	for (int i = 0; i < 3; i++)
		scanf("%d", &MAX[i]);
	for (int i = 0; i < 3; i++)
		scanf("%d", &ile[i]);
	
	odw[{ile[0], {ile[1], ile[2]}}] = 0;
	q.push({ile[0], {ile[1], ile[2]}});
	while(q.size() > 0) {
		v.clear();
		v.push_back(q.front().first);
		v.push_back(q.front().second.first);
		v.push_back(q.front().second.second);
		q.pop();

		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				if (i != j)
					przelej(i, j);
	}
	for (int i = 0; i <= MAX[2]; i++)	
		odp[i] = -1;

	for (auto x : odw) {
		std::pair<int, std::pair<int, int> > wyn = x.first;
		int wart[3] = {wyn.first, wyn.second.first, wyn.second.second};
		for (int i = 0; i < 3; i++) 
			if (odp[wart[i]] == -1)
				odp[wart[i]] = x.second;
			else 
				odp[wart[i]] = std::min(odp[wart[i]], x.second);
	}
	for (int i = 0; i <= MAX[2]; i++)
		printf("%d ", odp[i]);
	printf("\n");
}