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

int A[3];

struct butle {
	int a[3],n;
	butle(int a[],int n):n(n) {
		for (int i=0;i<3;i++) this->a[i]=a[i];
	}
	butle(){n=0;}
	bool operator ()(butle b1, butle b2) const {
		if (b1.a[0]==b2.a[0])
			if (b1.a[1]==b2.a[1])
				return b1.a[2]<b2.a[2];
			else
				return b1.a[1]<b2.a[1];
		else
			return b1.a[0]<b2.a[0];
	}
};

ostream & operator<<(ostream &o, const butle &b) {
	return o << b.n << " ("<<b.a[0]<<","<<b.a[1]<<","<<b.a[2]<<")\n";
}

set<butle,butle> s;
set<butle>::iterator sit;
pair<set<butle>::iterator, bool> ret;

butle przelew(butle b, int i,int j) {
	int k = min(b.a[i],A[j]-b.a[j]);
	b.a[i]-=k;
	b.a[j]+=k;
	b.n++;
	return b;
}

int main() {
	ios_base::sync_with_stdio(0);
	for (int i=0;i<3;i++) cin >> A[i];
	int C=A[2];
	butle b; int suma=0;
	for (int i=0;i<3;i++) { cin >> b.a[i]; suma+=b.a[i];}
	for (int i=0;i<3;i++)
		A[i]=min(A[i],suma);
	//cout << A[0]<<" "<<A[1]<<" "<<A[2]<< endl;
	vector<int> answer(C+1,-1);
	s.insert(b);
	queue<butle> q; q.push(*s.begin());
	while (!q.empty()) {
		butle p = q.front(); q.pop();
		for (int i=0;i<3;i++)
			if (answer[p.a[i]]<0)
				answer[p.a[i]]=p.n;
		for (int i=0;i<3;i++)
			for (int j=0;j<3;j++) {
				if (i==j) continue;
				butle b = przelew(p,i,j);
				ret = s.insert(b);
				if (ret.second)
					q.push(b);
			}
	}
	//for (sit=s.begin();sit!=s.end();sit++)	cout << *sit;
	for (int i=0;i<=C;i++)
		cout << answer[i] << " ";
	return 0;
}