/* -*- coding: utf-8 -*- * * 158.cc: No.158 奇妙なお使い - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 10000; const int MAX_C0 = 10; const int MAX_C1 = 100; /* typedef */ /* global variables */ int dp[MAX_N + 1][MAX_C0 + 1][MAX_C1 + 1]; /* subroutines */ bool pay(int d, int a0, int a1, int a2, int &b0, int &b1, int &b2) { b0 = min(d / 1000, a0); b1 = min((d - 1000 * b0) / 100, a1); b2 = d - 1000 * b0 - 100 * b1; return (a2 >= b2); } /* main */ int main() { int a0, a1, a2; cin >> a0 >> a1 >> a2; int db, b0, b1, b2; cin >> db >> b0 >> b1 >> b2; int dc, c0, c1, c2; cin >> dc >> c0 >> c1 >> c2; memset(dp, -1, sizeof(dp)); dp[0][a0][a1] = a2; int maxd = 0; bool cont = true; for (int i = 0; cont && i <= MAX_N; i++) { cont = false; for (int j = 0; j <= MAX_C0; j++) for (int k = 0; k <= MAX_C1; k++) { int d0 = dp[i][j][k]; if (d0 >= 0) { int x0, x1, x2; if (pay(db, j, k, d0, x0, x1, x2)) { int jb = j - x0 + b0, kb = k - x1 + b1, d1 = d0 - x2 + b2; if (dp[i + 1][jb][kb] < d1) dp[i + 1][jb][kb] = d1, cont = true, maxd = i + 1; } if (pay(dc, j, k, d0, x0, x1, x2)) { int jc = j - x0 + c0, kc = k - x1 + c1, d1 = d0 - x2 + c2; if (dp[i + 1][jc][kc] < d1) dp[i + 1][jc][kc] = d1, cont = true, maxd = i + 1; } } } } printf("%d\n", maxd); return 0; }