結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 82 ms
10,772 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 66 ms
10,776 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 33 ms
10,844 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 53 ms
10,788 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 77 ms
10,796 KB
testcase_16 AC 67 ms
10,704 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 37 ms
10,760 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 33 ms
10,792 KB
testcase_22 AC 64 ms
10,776 KB
testcase_23 AC 774 ms
10,796 KB
testcase_24 AC 344 ms
10,780 KB
testcase_25 AC 3 ms
4,964 KB
testcase_26 AC 4 ms
4,964 KB
testcase_27 AC 3 ms
4,908 KB
testcase_28 AC 4 ms
4,944 KB
testcase_29 AC 8 ms
10,700 KB
testcase_30 AC 100 ms
6,900 KB
testcase_31 AC 101 ms
6,896 KB
testcase_32 AC 197 ms
6,872 KB
testcase_33 AC 195 ms
6,824 KB
testcase_34 AC 287 ms
6,812 KB
testcase_35 AC 288 ms
6,912 KB
testcase_36 AC 765 ms
10,788 KB
testcase_37 AC 78 ms
5,784 KB
testcase_38 AC 533 ms
10,776 KB
testcase_39 AC 128 ms
6,932 KB
testcase_40 AC 120 ms
6,420 KB
testcase_41 AC 738 ms
10,840 KB
testcase_42 AC 641 ms
10,836 KB
testcase_43 AC 23 ms
4,380 KB
testcase_44 AC 318 ms
10,800 KB
testcase_45 AC 204 ms
5,676 KB
testcase_46 AC 303 ms
6,680 KB
testcase_47 AC 430 ms
10,760 KB
testcase_48 AC 470 ms
10,732 KB
testcase_49 AC 44 ms
4,376 KB
testcase_50 AC 370 ms
10,732 KB
testcase_51 AC 92 ms
5,596 KB
testcase_52 AC 151 ms
6,044 KB
testcase_53 AC 496 ms
10,788 KB
testcase_54 AC 346 ms
10,840 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 = 1000000;

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