結果

問題 No.288 貯金箱の仕事
ユーザー bekasa001bekasa001
提出日時 2015-10-09 23:30:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,131 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 40,060 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 10:31:46
合計ジャッジ時間 3,219 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 68 ms
4,380 KB
testcase_24 AC 31 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 19 ms
4,380 KB
testcase_31 AC 19 ms
4,380 KB
testcase_32 AC 37 ms
4,376 KB
testcase_33 AC 36 ms
4,376 KB
testcase_34 AC 54 ms
4,376 KB
testcase_35 AC 53 ms
4,380 KB
testcase_36 AC 69 ms
4,380 KB
testcase_37 AC 21 ms
4,376 KB
testcase_38 AC 48 ms
4,376 KB
testcase_39 AC 24 ms
4,380 KB
testcase_40 AC 26 ms
4,376 KB
testcase_41 AC 64 ms
4,376 KB
testcase_42 AC 57 ms
4,380 KB
testcase_43 AC 21 ms
4,380 KB
testcase_44 AC 30 ms
4,380 KB
testcase_45 AC 53 ms
4,380 KB
testcase_46 AC 59 ms
4,376 KB
testcase_47 AC 40 ms
4,376 KB
testcase_48 AC 42 ms
4,376 KB
testcase_49 AC 29 ms
4,376 KB
testcase_50 AC 36 ms
4,376 KB
testcase_51 AC 27 ms
4,376 KB
testcase_52 AC 37 ms
4,380 KB
testcase_53 AC 49 ms
4,376 KB
testcase_54 AC 35 ms
4,380 KB
testcase_55 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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