結果

問題 No.288 貯金箱の仕事
ユーザー bekasa001bekasa001
提出日時 2015-10-09 23:31:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 1,131 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 40,028 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2023-09-27 10:31:54
合計ジャッジ時間 7,217 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 38 ms
6,812 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 31 ms
6,876 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 15 ms
6,872 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 25 ms
6,900 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 35 ms
6,896 KB
testcase_16 AC 32 ms
6,876 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 18 ms
6,928 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 16 ms
6,892 KB
testcase_22 AC 31 ms
6,892 KB
testcase_23 AC 351 ms
6,900 KB
testcase_24 AC 151 ms
6,952 KB
testcase_25 AC 3 ms
4,932 KB
testcase_26 AC 2 ms
4,936 KB
testcase_27 AC 3 ms
4,932 KB
testcase_28 AC 3 ms
4,940 KB
testcase_29 AC 4 ms
6,792 KB
testcase_30 AC 93 ms
6,932 KB
testcase_31 AC 93 ms
6,888 KB
testcase_32 AC 179 ms
6,880 KB
testcase_33 AC 184 ms
6,924 KB
testcase_34 AC 268 ms
6,840 KB
testcase_35 AC 270 ms
6,872 KB
testcase_36 AC 346 ms
6,936 KB
testcase_37 AC 76 ms
5,792 KB
testcase_38 AC 249 ms
6,876 KB
testcase_39 AC 116 ms
6,888 KB
testcase_40 AC 110 ms
6,572 KB
testcase_41 AC 335 ms
6,912 KB
testcase_42 AC 289 ms
6,944 KB
testcase_43 AC 21 ms
4,380 KB
testcase_44 AC 145 ms
6,800 KB
testcase_45 AC 187 ms
5,732 KB
testcase_46 AC 284 ms
6,696 KB
testcase_47 AC 207 ms
6,864 KB
testcase_48 AC 215 ms
6,852 KB
testcase_49 AC 41 ms
4,380 KB
testcase_50 AC 168 ms
6,856 KB
testcase_51 AC 86 ms
5,700 KB
testcase_52 AC 139 ms
6,012 KB
testcase_53 AC 225 ms
6,904 KB
testcase_54 AC 160 ms
6,892 KB
testcase_55 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
typedef long long llint;
using namespace std;

const llint INF = 1e18;
const int KIJUN = 500000;

bool inmin(llint &a, const llint b) {
  if(b < a) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  llint M;
  if(scanf("%d%lld", &N, &M) == EOF) {
    return 0;
  }
  int A[N];
  for(int i = 0; i < N; i++) {
    if(scanf("%d", A + i) == EOF) {
      return 0;
    }
  }
  llint K[N];
  for(int i = 0; i < N; i++) {
    if(scanf("%lld", K + i) == EOF) {
      return 0;
    }
  }
  llint max = 0;
  for(int i = 0; i < N; i++) {
    max += K[i] * (llint)(A[i]);
  }
  if(M > max) {
    printf("-1\n");
    return 0;
  }
  llint ans = 0;
  llint tgt = max - M;
  if(tgt > KIJUN) {
    llint num = (tgt - KIJUN) / A[N - 1];
    ans += num;
    tgt -= (num * A[N - 1]);
  }
  llint dp[tgt + 1];
  fill(dp, dp + tgt + 1, INF);
  dp[0] = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j + A[i] <= tgt; j++) {
      inmin(dp[j + A[i]], dp[j] + 1);
    }
  }
  if(dp[tgt] == INF) {
    printf("-1\n");
  } else {
    printf("%lld\n", dp[tgt] + ans);
  }
  return 0;
}
0