結果

問題 No.288 貯金箱の仕事
ユーザー chocoruskchocorusk
提出日時 2018-12-11 21:42:32
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 943 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 96,448 KB
実行使用メモリ 5,628 KB
最終ジャッジ日時 2023-10-24 02:01:58
合計ジャッジ時間 10,481 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,628 KB
testcase_01 AC 4 ms
5,628 KB
testcase_02 AC 4 ms
5,628 KB
testcase_03 AC 3 ms
5,628 KB
testcase_04 AC 4 ms
5,628 KB
testcase_05 AC 4 ms
5,628 KB
testcase_06 AC 3 ms
5,628 KB
testcase_07 RE -
testcase_08 AC 6 ms
5,628 KB
testcase_09 RE -
testcase_10 AC 12 ms
5,628 KB
testcase_11 RE -
testcase_12 AC 11 ms
5,628 KB
testcase_13 RE -
testcase_14 AC 11 ms
5,628 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 9 ms
5,628 KB
testcase_18 RE -
testcase_19 AC 8 ms
5,628 KB
testcase_20 AC 7 ms
5,628 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 3 ms
5,628 KB
testcase_26 AC 4 ms
5,628 KB
testcase_27 AC 3 ms
5,628 KB
testcase_28 AC 3 ms
5,628 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 60 ms
5,628 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 41 ms
5,628 KB
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 4 ms
5,628 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[250001];
	fill(dp, dp+250000, INF);
	dp[0]=0;
	for(int i=0; i<n-1; i++){
		for(int j=0; j<=250000-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<=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