結果

問題 No.288 貯金箱の仕事
ユーザー te-shte-sh
提出日時 2017-06-08 15:54:39
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 781 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 1,435 ms
コンパイル使用メモリ 151,632 KB
実行使用メモリ 495,128 KB
最終ジャッジ日時 2023-09-03 14:03:30
合計ジャッジ時間 13,465 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,504 KB
testcase_23 AC 781 ms
495,128 KB
testcase_24 AC 298 ms
249,324 KB
testcase_25 AC 5 ms
5,852 KB
testcase_26 AC 5 ms
6,400 KB
testcase_27 AC 5 ms
5,808 KB
testcase_28 AC 5 ms
5,828 KB
testcase_29 AC 5 ms
5,876 KB
testcase_30 AC 164 ms
128,424 KB
testcase_31 AC 164 ms
128,732 KB
testcase_32 AC 326 ms
251,264 KB
testcase_33 AC 324 ms
251,076 KB
testcase_34 AC 530 ms
372,428 KB
testcase_35 AC 530 ms
372,400 KB
testcase_36 AC 734 ms
495,020 KB
testcase_37 AC 178 ms
141,108 KB
testcase_38 AC 471 ms
337,260 KB
testcase_39 AC 208 ms
166,420 KB
testcase_40 AC 214 ms
170,928 KB
testcase_41 AC 694 ms
473,016 KB
testcase_42 AC 592 ms
411,464 KB
testcase_43 AC 74 ms
58,788 KB
testcase_44 AC 108 ms
85,748 KB
testcase_45 AC 409 ms
267,480 KB
testcase_46 AC 598 ms
416,380 KB
testcase_47 AC 258 ms
204,916 KB
testcase_48 AC 384 ms
286,760 KB
testcase_49 AC 143 ms
111,044 KB
testcase_50 AC 225 ms
177,780 KB
testcase_51 AC 151 ms
119,232 KB
testcase_52 AC 288 ms
228,712 KB
testcase_53 AC 401 ms
296,192 KB
testcase_54 AC 210 ms
166,432 KB
testcase_55 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

const inf = 10 ^^ 9;

void main()
{
  auto rd = readln.split, n = rd[0].to!size_t, m = rd[1].to!long;
  auto ai = readln.split.to!(int[]);
  auto ki = readln.split.to!(long[]);

  auto b = zip(ai, ki).map!"a[0] * a[1]".sum;
  if (b < m) {
    writeln(-1);
    return;
  }

  auto c = b - m;
  auto r = max((c - ai[$-1] ^^ 2) / ai[$-1], 0);
  c -= r * ai[$-1];

  auto dp = new int[][](n+1, c+1);
  foreach (ref dpi; dp) dpi[] = inf;
  dp[0][0] = 0;

  foreach (i; 0..n) {
    foreach (j; 0..c+1) {
      dp[i+1][j] = dp[i][j];
      if (j >= ai[i])
        dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-ai[i]] + 1);
    }
  }

  auto s = dp[$-1][$-1];
  if (s == inf)
    writeln(-1);
  else
    writeln(r + s);
}
0