結果

問題 No.288 貯金箱の仕事
ユーザー koyumeishikoyumeishi
提出日時 2015-10-10 07:10:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 75,592 KB
実行使用メモリ 5,104 KB
最終ジャッジ日時 2023-09-27 10:45:15
合計ジャッジ時間 4,763 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,824 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 135 ms
4,900 KB
testcase_24 AC 69 ms
4,904 KB
testcase_25 AC 3 ms
4,900 KB
testcase_26 AC 4 ms
4,812 KB
testcase_27 AC 3 ms
4,864 KB
testcase_28 AC 4 ms
4,860 KB
testcase_29 AC 4 ms
4,860 KB
testcase_30 AC 37 ms
5,060 KB
testcase_31 AC 37 ms
4,896 KB
testcase_32 AC 70 ms
4,856 KB
testcase_33 AC 70 ms
4,900 KB
testcase_34 AC 102 ms
5,096 KB
testcase_35 AC 102 ms
4,960 KB
testcase_36 AC 135 ms
4,904 KB
testcase_37 AC 40 ms
4,820 KB
testcase_38 AC 93 ms
4,880 KB
testcase_39 AC 47 ms
5,104 KB
testcase_40 AC 48 ms
4,864 KB
testcase_41 AC 130 ms
4,960 KB
testcase_42 AC 112 ms
4,816 KB
testcase_43 AC 81 ms
4,844 KB
testcase_44 AC 24 ms
4,380 KB
testcase_45 AC 74 ms
4,380 KB
testcase_46 AC 114 ms
4,908 KB
testcase_47 AC 57 ms
4,380 KB
testcase_48 AC 79 ms
4,876 KB
testcase_49 AC 34 ms
4,376 KB
testcase_50 AC 50 ms
4,376 KB
testcase_51 AC 36 ms
4,380 KB
testcase_52 AC 64 ms
4,816 KB
testcase_53 AC 81 ms
4,872 KB
testcase_54 AC 47 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

int main(){
	long long n,m;
	cin >> n >> m;
	vector<long long> a(n), k(n);

	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<n; i++){
		cin >> k[i];
	}

	long long sum = 0;
	for(int i=0; i<n; i++){
		sum += a[i] * k[i];
	}

	sum -= m;
	if(sum<0){
		cout << -1 << endl;

		return 0;
	}

	long long cnt = 0;

	long long sz = a[n-1]*a[n-1]+1;
	vector<long long> dp(sz, 1LL<<50);
	dp[0] = 0;
	for(int i=0; i<n; i++){
		for(long long v=a[i]; v<sz; v++){
			dp[v] = min(dp[v], dp[v-a[i]] + 1);
		}

	}

	auto check = [&](long long x){
		return a.back()*a.back() < sum - x*a.back();
	};

	long long lb = sum/(a.back()*a.back());
	lb *= a.back();

	/*
	long long ub = 1e13;
	while(ub-lb>1){
		long long mid = (lb+ub)/2;
		bool ok = check(mid);
		(ok? lb : ub) = mid;
	}
	*/

	cnt += lb;
	sum -= lb*a.back();

	cnt = dp[sum]!=(1LL<<50)?(cnt+dp[sum]):-1;

	cout << cnt << endl;

	return 0;
}
0