結果

問題 No.288 貯金箱の仕事
ユーザー pekempeypekempey
提出日時 2015-10-10 00:10:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 1,308 bytes
コンパイル時間 2,604 ms
コンパイル使用メモリ 144,944 KB
実行使用メモリ 6,180 KB
最終ジャッジ日時 2023-09-27 10:40:30
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,816 KB
testcase_01 AC 5 ms
6,096 KB
testcase_02 AC 6 ms
5,808 KB
testcase_03 AC 4 ms
6,020 KB
testcase_04 AC 5 ms
5,868 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 29 ms
5,808 KB
testcase_08 AC 12 ms
5,928 KB
testcase_09 AC 23 ms
5,916 KB
testcase_10 AC 25 ms
5,928 KB
testcase_11 AC 13 ms
5,932 KB
testcase_12 AC 23 ms
5,808 KB
testcase_13 AC 19 ms
5,808 KB
testcase_14 AC 23 ms
6,160 KB
testcase_15 AC 28 ms
6,160 KB
testcase_16 AC 25 ms
5,904 KB
testcase_17 AC 19 ms
5,992 KB
testcase_18 AC 14 ms
6,016 KB
testcase_19 AC 17 ms
5,864 KB
testcase_20 AC 12 ms
6,024 KB
testcase_21 AC 13 ms
5,820 KB
testcase_22 AC 23 ms
5,856 KB
testcase_23 AC 268 ms
5,916 KB
testcase_24 AC 148 ms
5,868 KB
testcase_25 AC 5 ms
6,020 KB
testcase_26 AC 4 ms
5,912 KB
testcase_27 AC 5 ms
6,016 KB
testcase_28 AC 5 ms
6,028 KB
testcase_29 AC 5 ms
5,920 KB
testcase_30 AC 68 ms
5,812 KB
testcase_31 AC 68 ms
5,860 KB
testcase_32 AC 133 ms
5,904 KB
testcase_33 AC 133 ms
6,176 KB
testcase_34 AC 199 ms
5,916 KB
testcase_35 AC 200 ms
6,080 KB
testcase_36 AC 267 ms
6,180 KB
testcase_37 AC 77 ms
5,976 KB
testcase_38 AC 184 ms
5,824 KB
testcase_39 AC 89 ms
6,160 KB
testcase_40 AC 92 ms
5,872 KB
testcase_41 AC 256 ms
5,820 KB
testcase_42 AC 222 ms
6,076 KB
testcase_43 AC 154 ms
5,912 KB
testcase_44 AC 108 ms
5,988 KB
testcase_45 AC 204 ms
5,912 KB
testcase_46 AC 224 ms
5,872 KB
testcase_47 AC 146 ms
5,972 KB
testcase_48 AC 160 ms
5,908 KB
testcase_49 AC 97 ms
5,860 KB
testcase_50 AC 128 ms
5,820 KB
testcase_51 AC 93 ms
6,100 KB
testcase_52 AC 130 ms
5,868 KB
testcase_53 AC 169 ms
5,908 KB
testcase_54 AC 117 ms
6,096 KB
testcase_55 AC 5 ms
5,868 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) / 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