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
#include <cstdio>
#include <set>
#include <vector>

typedef long long LL;

const int MAXN = 100000 + 1;
const int INF = (LL(1) << 31) - 1;

using namespace std;

int a[3];
set<vector<int>> visited;

vector<int> g(vector<int> v, int i, int j) {
    int d = min(v[i], a[j] - v[j]);
    v[i] -= d;
    v[j] += d;
    return v;
}

int res[MAXN];

int main() {
    vector<int> v(3);
    for (int i = 0; i < 3; i++) scanf("%d", &a[i]);
    for (int i = 0; i < 3; i++) scanf("%d", &v[i]);
    for (int i = 0; i <= a[2]; i++) res[i] = INF;

    vector<vector<int>> q;
    int d = 0;
    q.push_back(v);
    while (!q.empty()) {
        vector<vector<int>> q2;
        q2.clear();
        for (auto it = q.begin(); it != q.end(); it++) {

            for (auto it2 = it->begin(); it2 != it->end(); it2++)
                res[*it2] = min(res[*it2], d);

            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    if (i == j) continue;
                    auto v2 = g(*it, i, j);
                    if (visited.find(v2) != visited.end()) continue;
                    visited.insert(v2);
                    q2.push_back(v2);
                }
            }
        }
        swap(q, q2);
        d++;
    }

    for (int i = 0; i <= a[2]; i++) {
        if (res[i] == INF) res[i] = -1;
        printf("%d ", res[i]);
    }
    printf("\n");
}