結果

問題 No.288 貯金箱の仕事
ユーザー chocoruskchocorusk
提出日時 2018-12-11 21:48:35
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 962 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 96,588 KB
実行使用メモリ 11,496 KB
最終ジャッジ日時 2023-10-24 02:27:00
合計ジャッジ時間 9,485 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
11,464 KB
testcase_01 AC 9 ms
11,464 KB
testcase_02 AC 11 ms
11,464 KB
testcase_03 AC 8 ms
11,464 KB
testcase_04 AC 12 ms
11,464 KB
testcase_05 AC 7 ms
11,464 KB
testcase_06 AC 7 ms
11,464 KB
testcase_07 AC 50 ms
11,464 KB
testcase_08 AC 20 ms
11,464 KB
testcase_09 AC 41 ms
11,464 KB
testcase_10 AC 43 ms
11,464 KB
testcase_11 AC 25 ms
11,464 KB
testcase_12 AC 40 ms
11,464 KB
testcase_13 AC 33 ms
11,464 KB
testcase_14 AC 40 ms
11,464 KB
testcase_15 WA -
testcase_16 AC 42 ms
11,464 KB
testcase_17 AC 32 ms
11,464 KB
testcase_18 AC 26 ms
11,464 KB
testcase_19 AC 29 ms
11,464 KB
testcase_20 AC 20 ms
11,464 KB
testcase_21 AC 24 ms
11,464 KB
testcase_22 AC 41 ms
11,464 KB
testcase_23 AC 398 ms
11,464 KB
testcase_24 AC 204 ms
11,464 KB
testcase_25 AC 9 ms
11,464 KB
testcase_26 AC 9 ms
11,464 KB
testcase_27 AC 9 ms
11,464 KB
testcase_28 AC 9 ms
11,464 KB
testcase_29 AC 9 ms
11,464 KB
testcase_30 AC 111 ms
11,464 KB
testcase_31 AC 110 ms
11,464 KB
testcase_32 AC 208 ms
11,464 KB
testcase_33 AC 206 ms
11,464 KB
testcase_34 AC 307 ms
11,464 KB
testcase_35 AC 304 ms
11,464 KB
testcase_36 AC 402 ms
11,464 KB
testcase_37 AC 119 ms
11,464 KB
testcase_38 AC 282 ms
11,464 KB
testcase_39 AC 136 ms
11,464 KB
testcase_40 AC 143 ms
11,464 KB
testcase_41 AC 385 ms
11,464 KB
testcase_42 AC 338 ms
11,464 KB
testcase_43 AC 239 ms
11,464 KB
testcase_44 AC 169 ms
11,464 KB
testcase_45 AC 312 ms
11,464 KB
testcase_46 AC 338 ms
11,464 KB
testcase_47 AC 226 ms
11,464 KB
testcase_48 AC 249 ms
11,464 KB
testcase_49 AC 153 ms
11,464 KB
testcase_50 AC 198 ms
11,464 KB
testcase_51 AC 148 ms
11,464 KB
testcase_52 AC 203 ms
11,464 KB
testcase_53 AC 260 ms
11,464 KB
testcase_54 AC 183 ms
11,464 KB
testcase_55 AC 10 ms
11,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e18+1;
int main()
{
	int n; ll m;
	cin>>n>>m;
	ll a[500];
	for(int i=0; i<n; i++) cin>>a[i];
	ll s=0;
	for(int i=0; i<n; i++){
		ll k; cin>>k;
		s+=(a[i]*k);
	}
	if(s<m){
		cout<<-1<<endl;
		return 0;
	}
	s-=m;
	ll dp[1000001];
	fill(dp, dp+1000000, INF);
	dp[0]=0;
	for(int i=0; i<n-1; i++){
		for(int j=0; j<=1000000-a[i]; j++){
			dp[j+a[i]]=min(dp[j]+1, dp[j+a[i]]);
		}
	}
	ll ans=INF;
	for(ll i=s%a[n-1]; i<=min(1000000ll, s); i+=a[n-1]){
		if(dp[i]==INF) continue;
		ans=min(ans, dp[i]+(s-i)/a[n-1]);
	}
	if(ans<INF) cout<<ans<<endl;
	else cout<<-1<<endl;
	return 0;
}
0