結果

問題 No.288 貯金箱の仕事
ユーザー pekempeypekempey
提出日時 2015-10-10 00:08:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 145,280 KB
実行使用メモリ 6,184 KB
最終ジャッジ日時 2023-09-27 10:40:20
合計ジャッジ時間 7,531 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,096 KB
testcase_01 AC 5 ms
5,916 KB
testcase_02 AC 5 ms
5,916 KB
testcase_03 AC 5 ms
5,928 KB
testcase_04 AC 5 ms
5,920 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 29 ms
5,892 KB
testcase_08 AC 11 ms
6,176 KB
testcase_09 AC 24 ms
6,184 KB
testcase_10 AC 26 ms
5,964 KB
testcase_11 AC 13 ms
5,932 KB
testcase_12 AC 23 ms
6,080 KB
testcase_13 AC 20 ms
6,016 KB
testcase_14 AC 23 ms
5,928 KB
testcase_15 AC 27 ms
5,968 KB
testcase_16 AC 24 ms
5,944 KB
testcase_17 AC 19 ms
6,024 KB
testcase_18 AC 14 ms
6,032 KB
testcase_19 AC 17 ms
5,896 KB
testcase_20 AC 12 ms
5,956 KB
testcase_21 AC 13 ms
5,968 KB
testcase_22 WA -
testcase_23 AC 267 ms
5,928 KB
testcase_24 AC 147 ms
5,888 KB
testcase_25 AC 5 ms
6,048 KB
testcase_26 AC 5 ms
5,968 KB
testcase_27 AC 5 ms
5,944 KB
testcase_28 AC 5 ms
5,988 KB
testcase_29 AC 5 ms
6,080 KB
testcase_30 AC 69 ms
6,024 KB
testcase_31 AC 68 ms
6,044 KB
testcase_32 AC 133 ms
5,928 KB
testcase_33 AC 133 ms
5,916 KB
testcase_34 AC 199 ms
5,932 KB
testcase_35 AC 200 ms
5,932 KB
testcase_36 AC 267 ms
5,936 KB
testcase_37 AC 77 ms
5,892 KB
testcase_38 AC 184 ms
5,988 KB
testcase_39 AC 90 ms
5,924 KB
testcase_40 AC 92 ms
5,888 KB
testcase_41 AC 256 ms
6,172 KB
testcase_42 AC 222 ms
5,892 KB
testcase_43 AC 153 ms
6,024 KB
testcase_44 AC 107 ms
5,928 KB
testcase_45 AC 202 ms
5,956 KB
testcase_46 AC 223 ms
5,936 KB
testcase_47 AC 147 ms
6,176 KB
testcase_48 AC 160 ms
5,920 KB
testcase_49 AC 97 ms
5,924 KB
testcase_50 AC 126 ms
5,968 KB
testcase_51 AC 92 ms
5,984 KB
testcase_52 AC 130 ms
5,924 KB
testcase_53 AC 169 ms
5,892 KB
testcase_54 AC 118 ms
6,024 KB
testcase_55 AC 5 ms
5,920 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 = 333333;
ll N, M;
ll A[500], K[500];
int dp[2][MX];

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

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);
		cout << ans << endl;
	}
	return 0;
}
0