#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define inf 0x3f3f3f3f #define uinf 0x3f3f3f3f3f3f3f3f #define CLEAR(a) a = decltype(a)() #define MP make_pair #define ALL(a) (a).begin(),(a).end() #define pii pair #define pcc pair #define pic pair #define pci pair #define vs vector #define vi vector #define vii vector> #define DEBUG(x) cout<<#x<<": "<> N >> M; vector A(N); for (auto &a : A) cin >> a; vector K(N); for (auto &a : K) cin >> a; int diff = 0; //pay REP(i, N) diff += A[i] * K[i]; diff -= M; if (diff < 0) { cout << -1 << endl; return 0; } vector dp(A.back()*A.back(), uinf); // = お釣りの最小枚数 dp[0] = 0; if (diff >= dp.size()) { int c = (diff - dp.size()) / A.back(); ++c; diff -= c*A.back(); dp[0] = c; } REP(i, dp.size()) REP(j, A.size()) if (i - A[j] >= 0) dp[i] = min(dp[i], dp[i - A[j]] + 1); if (dp[diff] >= uinf) cout << -1 << endl; else cout << dp[diff] << endl; return 0; }