結果

問題 No.288 貯金箱の仕事
ユーザー pekempeypekempey
提出日時 2015-10-09 23:25:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,294 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 144,920 KB
実行使用メモリ 501,720 KB
最終ジャッジ日時 2023-09-27 10:30:32
合計ジャッジ時間 16,216 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
501,464 KB
testcase_01 AC 168 ms
501,600 KB
testcase_02 AC 168 ms
501,468 KB
testcase_03 AC 167 ms
501,516 KB
testcase_04 AC 168 ms
501,716 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 174 ms
501,568 KB
testcase_09 WA -
testcase_10 AC 185 ms
501,396 KB
testcase_11 WA -
testcase_12 AC 182 ms
501,488 KB
testcase_13 WA -
testcase_14 AC 182 ms
501,360 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 178 ms
501,404 KB
testcase_18 WA -
testcase_19 AC 177 ms
501,464 KB
testcase_20 AC 173 ms
501,516 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 169 ms
501,408 KB
testcase_26 AC 167 ms
501,516 KB
testcase_27 AC 168 ms
501,452 KB
testcase_28 AC 170 ms
501,512 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 284 ms
501,420 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 239 ms
501,556 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 166 ms
501,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

const ll inf = 1e9;
const ll MX = 252525;
ll N, M;
ll A[500], K[500];
int dp[505][MX];

ll solve(ll D) {
	rep (i, 505) rep (j, MX) dp[i][j] = inf;
	dp[0][0] = 0;
	rep (i, N) {
		rep (j, MX) {
			chmin(dp[i + 1][j], dp[i][j]);
			if (j - A[i] >= 0) {
				chmin(dp[i + 1][j], dp[i + 1][j - A[i]] + 1);
			}
		}
	}
	if (D < MX) {
		return dp[N][D];
	} else {
		ll mx = *max_element(A, A + N);
		ll num = (D - MX) / mx;
		D -= num * mx;
		return dp[N][D] + num;
	}
}

int main() {
	cin >> N >> M;
	rep (i, N) cin >> A[i];
	rep (i, N) cin >> K[i];
	ll mx = 0;
	rep (i, N) mx += A[i] * K[i];
	ll D = mx - M;
	if (D < 0) {
		cout << -1 << endl;	
	} else {
		ll ans = solve(D);
		if (ans >= inf) {
			cout << -1 << endl;
		} else {
			cout << ans << endl;
		}
	}
	return 0;
}
0