結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 68 ms
10,048 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 56 ms
9,992 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 26 ms
10,056 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 44 ms
10,036 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 63 ms
10,032 KB
testcase_16 AC 56 ms
10,012 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 29 ms
9,896 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 28 ms
9,940 KB
testcase_22 AC 53 ms
10,060 KB
testcase_23 AC 654 ms
10,044 KB
testcase_24 AC 295 ms
10,052 KB
testcase_25 AC 3 ms
4,860 KB
testcase_26 AC 3 ms
4,920 KB
testcase_27 AC 3 ms
4,952 KB
testcase_28 AC 3 ms
4,924 KB
testcase_29 AC 7 ms
10,020 KB
testcase_30 AC 93 ms
6,896 KB
testcase_31 AC 88 ms
6,932 KB
testcase_32 AC 177 ms
6,856 KB
testcase_33 AC 181 ms
6,888 KB
testcase_34 AC 267 ms
6,928 KB
testcase_35 AC 265 ms
6,860 KB
testcase_36 AC 658 ms
10,020 KB
testcase_37 AC 76 ms
5,772 KB
testcase_38 AC 454 ms
10,016 KB
testcase_39 AC 118 ms
6,936 KB
testcase_40 AC 112 ms
6,580 KB
testcase_41 AC 624 ms
10,008 KB
testcase_42 AC 532 ms
10,076 KB
testcase_43 AC 21 ms
4,376 KB
testcase_44 AC 268 ms
10,004 KB
testcase_45 AC 188 ms
5,596 KB
testcase_46 AC 277 ms
6,672 KB
testcase_47 AC 353 ms
10,012 KB
testcase_48 AC 387 ms
10,092 KB
testcase_49 AC 40 ms
4,376 KB
testcase_50 AC 304 ms
9,980 KB
testcase_51 AC 86 ms
5,656 KB
testcase_52 AC 142 ms
6,032 KB
testcase_53 AC 407 ms
10,016 KB
testcase_54 AC 280 ms
9,996 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 = 900000;

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