結果

問題 No.288 貯金箱の仕事
ユーザー bekasa001bekasa001
提出日時 2015-10-09 23:24:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 971 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 39,548 KB
実行使用メモリ 6,888 KB
最終ジャッジ日時 2023-09-27 10:29:04
合計ジャッジ時間 8,457 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 RE -
testcase_08 AC 1 ms
4,380 KB
testcase_09 RE -
testcase_10 AC 1 ms
4,380 KB
testcase_11 RE -
testcase_12 AC 2 ms
4,376 KB
testcase_13 RE -
testcase_14 AC 1 ms
4,376 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 2 ms
4,376 KB
testcase_18 RE -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 4 ms
4,912 KB
testcase_26 AC 3 ms
4,888 KB
testcase_27 AC 4 ms
4,944 KB
testcase_28 AC 4 ms
4,904 KB
testcase_29 RE -
testcase_30 AC 100 ms
6,888 KB
testcase_31 AC 101 ms
6,844 KB
testcase_32 AC 196 ms
6,796 KB
testcase_33 AC 194 ms
6,816 KB
testcase_34 AC 286 ms
6,800 KB
testcase_35 AC 286 ms
6,880 KB
testcase_36 RE -
testcase_37 AC 78 ms
5,668 KB
testcase_38 RE -
testcase_39 AC 127 ms
6,836 KB
testcase_40 AC 121 ms
6,524 KB
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 24 ms
4,376 KB
testcase_44 RE -
testcase_45 AC 207 ms
5,692 KB
testcase_46 AC 302 ms
6,664 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 45 ms
4,380 KB
testcase_50 RE -
testcase_51 AC 93 ms
5,584 KB
testcase_52 AC 149 ms
6,024 KB
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const llint INF = 1e18;

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 tgt = max - M;
  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]);
  }
  return 0;
}
0