結果

問題 No.288 貯金箱の仕事
ユーザー pekempeypekempey
提出日時 2015-10-10 17:51:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 1,214 ms
コンパイル使用メモリ 144,728 KB
実行使用メモリ 6,156 KB
最終ジャッジ日時 2023-09-28 11:34:40
合計ジャッジ時間 6,546 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,028 KB
testcase_01 AC 4 ms
5,912 KB
testcase_02 AC 5 ms
6,024 KB
testcase_03 AC 4 ms
5,984 KB
testcase_04 AC 5 ms
5,960 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 23 ms
5,956 KB
testcase_08 AC 9 ms
5,948 KB
testcase_09 AC 19 ms
5,920 KB
testcase_10 AC 21 ms
6,088 KB
testcase_11 AC 11 ms
6,136 KB
testcase_12 AC 18 ms
5,904 KB
testcase_13 AC 15 ms
5,980 KB
testcase_14 AC 18 ms
6,024 KB
testcase_15 AC 22 ms
5,952 KB
testcase_16 AC 20 ms
6,020 KB
testcase_17 AC 15 ms
5,908 KB
testcase_18 AC 12 ms
5,956 KB
testcase_19 AC 14 ms
6,020 KB
testcase_20 AC 10 ms
6,080 KB
testcase_21 AC 11 ms
5,920 KB
testcase_22 AC 18 ms
5,960 KB
testcase_23 AC 202 ms
6,148 KB
testcase_24 AC 101 ms
6,136 KB
testcase_25 AC 5 ms
5,960 KB
testcase_26 AC 4 ms
5,912 KB
testcase_27 AC 4 ms
5,920 KB
testcase_28 AC 4 ms
5,956 KB
testcase_29 AC 4 ms
5,920 KB
testcase_30 AC 53 ms
5,952 KB
testcase_31 AC 53 ms
5,964 KB
testcase_32 AC 102 ms
5,964 KB
testcase_33 AC 101 ms
5,960 KB
testcase_34 AC 151 ms
6,024 KB
testcase_35 AC 151 ms
5,920 KB
testcase_36 AC 202 ms
6,004 KB
testcase_37 AC 58 ms
5,972 KB
testcase_38 AC 141 ms
5,920 KB
testcase_39 AC 68 ms
6,016 KB
testcase_40 AC 70 ms
5,972 KB
testcase_41 AC 193 ms
6,020 KB
testcase_42 AC 170 ms
5,956 KB
testcase_43 AC 117 ms
5,968 KB
testcase_44 AC 83 ms
6,152 KB
testcase_45 AC 154 ms
6,156 KB
testcase_46 AC 169 ms
5,916 KB
testcase_47 AC 112 ms
5,948 KB
testcase_48 AC 122 ms
5,956 KB
testcase_49 AC 74 ms
5,960 KB
testcase_50 AC 96 ms
5,920 KB
testcase_51 AC 70 ms
5,928 KB
testcase_52 AC 99 ms
6,024 KB
testcase_53 AC 128 ms
6,020 KB
testcase_54 AC 89 ms
6,016 KB
testcase_55 AC 5 ms
5,916 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 = 2e18;
const ll MX = 333333;
ll dp[MX], A[500], K[500];

int main() {
	ll N, M;
	cin >> N >> M;
	rep (i, N) cin >> A[i];
	rep (i, N) cin >> K[i];
	ll sum = 0;
	rep (i, N) sum += A[i] * K[i];
	ll D = sum - M;
	if (D < 0) {
		cout << -1 << endl;
		return 0;
	}	
	rep (i, MX) dp[i] = inf;
	dp[0] = 0;
	rep (i, N) rep (j, A[i], MX) {
		chmin(dp[j], dp[j - A[i]] + 1);
	}
	ll mx = A[N - 1];
	ll num = max(0ll, (D - MX) / mx + 1);
	ll ans = dp[D - num * mx] + num;
	if (ans >= inf) ans = -1;
	cout << ans << endl;
	return 0;
}
0