結果

問題 No.288 貯金箱の仕事
ユーザー beetbeet
提出日時 2018-12-04 22:34:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 200,596 KB
実行使用メモリ 6,032 KB
最終ジャッジ日時 2023-09-22 18:15:21
合計ジャッジ時間 8,947 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,692 KB
testcase_01 AC 4 ms
5,736 KB
testcase_02 AC 5 ms
5,732 KB
testcase_03 AC 4 ms
6,008 KB
testcase_04 AC 5 ms
5,736 KB
testcase_05 AC 6 ms
5,872 KB
testcase_06 AC 4 ms
5,728 KB
testcase_07 AC 30 ms
5,680 KB
testcase_08 AC 10 ms
5,692 KB
testcase_09 AC 25 ms
5,680 KB
testcase_10 AC 24 ms
5,740 KB
testcase_11 AC 15 ms
5,696 KB
testcase_12 AC 21 ms
6,000 KB
testcase_13 AC 21 ms
5,740 KB
testcase_14 AC 21 ms
5,800 KB
testcase_15 AC 28 ms
5,696 KB
testcase_16 AC 25 ms
5,740 KB
testcase_17 AC 17 ms
5,740 KB
testcase_18 AC 16 ms
6,020 KB
testcase_19 AC 15 ms
5,684 KB
testcase_20 AC 11 ms
5,872 KB
testcase_21 AC 15 ms
5,684 KB
testcase_22 AC 24 ms
6,028 KB
testcase_23 AC 238 ms
5,888 KB
testcase_24 AC 109 ms
5,676 KB
testcase_25 AC 7 ms
5,696 KB
testcase_26 AC 6 ms
5,676 KB
testcase_27 AC 7 ms
5,768 KB
testcase_28 AC 7 ms
5,692 KB
testcase_29 AC 8 ms
5,736 KB
testcase_30 AC 64 ms
5,876 KB
testcase_31 AC 64 ms
5,964 KB
testcase_32 AC 123 ms
5,752 KB
testcase_33 AC 122 ms
5,672 KB
testcase_34 AC 180 ms
6,032 KB
testcase_35 AC 179 ms
5,884 KB
testcase_36 AC 236 ms
5,752 KB
testcase_37 AC 71 ms
5,744 KB
testcase_38 AC 164 ms
5,744 KB
testcase_39 AC 84 ms
5,748 KB
testcase_40 AC 85 ms
5,740 KB
testcase_41 AC 226 ms
5,716 KB
testcase_42 AC 198 ms
5,756 KB
testcase_43 AC 138 ms
5,696 KB
testcase_44 AC 100 ms
6,000 KB
testcase_45 AC 183 ms
5,720 KB
testcase_46 AC 200 ms
5,820 KB
testcase_47 AC 135 ms
5,688 KB
testcase_48 AC 146 ms
5,700 KB
testcase_49 AC 88 ms
5,736 KB
testcase_50 AC 117 ms
5,892 KB
testcase_51 AC 87 ms
5,684 KB
testcase_52 AC 123 ms
5,696 KB
testcase_53 AC 153 ms
5,744 KB
testcase_54 AC 107 ms
5,712 KB
testcase_55 AC 5 ms
5,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 3e5;
Int dp[MAX];
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> a(n),b(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  for(Int i=0;i<n;i++) cin>>b[i];

  Int s=0;
  for(Int i=0;i<n;i++) s+=a[i]*b[i];
  
  const Int INF = 1e18+100;
  for(Int i=0;i<MAX;i++) dp[i]=INF;
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=0;j+a[i]<MAX;j++)
      chmin(dp[j+a[i]],dp[j]+1);

  Int ans=INF;
  for(Int i=0;i<MAX;i++){
    if(i>(s-m)||(s-m-i)%a[n-1]) continue;
    chmin(ans,dp[i]+(s-m-i)/a[n-1]);
  }
  
  if(ans>=INF) ans=-1;
  cout<<ans<<endl;
  return 0;
}
0