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
#include <map>
#include <queue>
#include <cstdio>

#define T vector<int>
#define IT pair<int, T>

using namespace std;

int a,b,c,pa,pb,pc;
int res[102030];

void solve() {
  map<T, int> minDist;
  priority_queue<IT> q;
  T start = { pa, pb, pc};
  q.push(make_pair(0, start));
  minDist[start] = 0;
  int av[3] = { a, b, c };
  while(!q.empty()) {
    auto cur = q.top();
    q.pop();
    int curDist = minDist[cur.second];
    if(cur.first <= curDist) {
      T& u = cur.second;
      for(int i=0;i<3;i++) for(int j=0;j<3;j++) if(i!=j) {
        int src = u[i];
        int dst = u[j];
        int avail = av[j] - dst;
        if(avail > 0) {
          T next = T(u);
          if(src <= avail) {
            next[i] = 0;
            next[j] = dst + src;
          } else {
            next[i] = src - avail;
            next[j] = av[j];
          }
          auto it = minDist.find(next);
          if((it == minDist.end()) || (it->second > curDist + 1)) {
            q.push(make_pair(curDist + 1, next));
            minDist[next] = curDist + 1;
          }
        }
      }
    }
  }
  for(auto it = minDist.begin();it!=minDist.end();it++) {
    for(auto v=it->first.begin();v!=it->first.end();v++) {
      int x = *v;
      if((x <= c) && ((res[x] == -1) || (res[x] > it->second))) {
        res[x] = it->second;
      }
    }
  }
}

int main(int argc, char** argv) {
  scanf("%d%d%d%d%d%d", &a, &b, &c, &pa, &pb, &pc);
  fill(res, res + c + 1, -1);
  solve();
  for(int i=0;i<=c;i++) {
    if(i > 0) {
      printf(" ");
    }
    printf("%d", res[i]);
  }
  printf("\n");
  return 0;
}