結果

問題 No.288 貯金箱の仕事
ユーザー youzohyouzoh
提出日時 2022-09-19 16:57:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 769 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 78,308 KB
最終ジャッジ日時 2023-08-23 18:59:00
合計ジャッジ時間 16,715 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
77,408 KB
testcase_01 AC 76 ms
75,568 KB
testcase_02 AC 70 ms
71,108 KB
testcase_03 AC 75 ms
71,112 KB
testcase_04 AC 70 ms
71,160 KB
testcase_05 AC 86 ms
77,408 KB
testcase_06 AC 71 ms
71,136 KB
testcase_07 AC 80 ms
75,768 KB
testcase_08 AC 77 ms
75,668 KB
testcase_09 AC 79 ms
75,612 KB
testcase_10 AC 81 ms
75,612 KB
testcase_11 AC 80 ms
75,672 KB
testcase_12 AC 79 ms
75,824 KB
testcase_13 AC 77 ms
75,744 KB
testcase_14 AC 79 ms
75,840 KB
testcase_15 AC 79 ms
75,552 KB
testcase_16 AC 79 ms
75,652 KB
testcase_17 AC 78 ms
75,572 KB
testcase_18 AC 79 ms
75,640 KB
testcase_19 AC 76 ms
75,516 KB
testcase_20 AC 76 ms
75,544 KB
testcase_21 AC 77 ms
75,624 KB
testcase_22 AC 79 ms
75,752 KB
testcase_23 AC 765 ms
78,308 KB
testcase_24 AC 498 ms
77,812 KB
testcase_25 AC 84 ms
77,580 KB
testcase_26 AC 84 ms
77,536 KB
testcase_27 AC 87 ms
77,748 KB
testcase_28 AC 84 ms
77,576 KB
testcase_29 AC 83 ms
77,516 KB
testcase_30 AC 227 ms
77,936 KB
testcase_31 AC 234 ms
77,768 KB
testcase_32 AC 390 ms
77,888 KB
testcase_33 AC 378 ms
78,196 KB
testcase_34 AC 558 ms
78,236 KB
testcase_35 AC 552 ms
78,180 KB
testcase_36 AC 769 ms
78,004 KB
testcase_37 AC 372 ms
77,632 KB
testcase_38 AC 541 ms
78,044 KB
testcase_39 AC 291 ms
77,824 KB
testcase_40 AC 308 ms
77,852 KB
testcase_41 AC 739 ms
78,044 KB
testcase_42 AC 648 ms
78,008 KB
testcase_43 AC 438 ms
77,920 KB
testcase_44 AC 189 ms
76,848 KB
testcase_45 AC 441 ms
77,216 KB
testcase_46 AC 632 ms
77,780 KB
testcase_47 AC 336 ms
77,856 KB
testcase_48 AC 446 ms
77,840 KB
testcase_49 AC 224 ms
76,848 KB
testcase_50 AC 291 ms
77,412 KB
testcase_51 AC 223 ms
77,196 KB
testcase_52 AC 362 ms
77,668 KB
testcase_53 AC 453 ms
77,968 KB
testcase_54 AC 286 ms
77,804 KB
testcase_55 AC 68 ms
71,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main() -> None:
  N, M = (int(elt) for elt in input().split())
  A = [int(elt) for elt in input().split()]
  K = [int(elt) for elt in input().split()]
  tot = sum(a * k for (a, k) in zip(A, K)) - M
  # print(f"DEBUG: tot={tot}")
  MAX_V = A[N - 1] * A[N -  1]
  INF = 10**18
  dp = [INF] * (MAX_V + 1)
  dp[0] = 0
  for i in range(N):
    for j in range(MAX_V + 1):
      if j - A[i] >= 0:
        dp[j] = min(dp[j], dp[j - A[i]] + 1)
  # print(f"DEBUG: dp={dp}")
  ans = INF
  for j in range(MAX_V + 1):
    if dp[j] == INF:
      continue
    rem = tot - j
    if rem >= 0 and rem % A[N - 1] == 0:
      ans = min(ans, dp[j] + (rem // A[N - 1]))
  if ans == INF:
    ans = -1
  print(ans)
  return


if __name__ == '__main__':
  main()
0