結果

問題 No.1163 I want to be a high achiever
ユーザー qibqib
提出日時 2023-03-02 20:47:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 849 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 143,336 KB
最終ジャッジ日時 2023-10-17 16:48:55
合計ジャッジ時間 11,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
66,352 KB
testcase_01 AC 35 ms
53,560 KB
testcase_02 AC 36 ms
53,560 KB
testcase_03 AC 41 ms
60,012 KB
testcase_04 AC 394 ms
101,408 KB
testcase_05 AC 630 ms
122,924 KB
testcase_06 AC 167 ms
77,680 KB
testcase_07 AC 752 ms
140,372 KB
testcase_08 AC 730 ms
138,792 KB
testcase_09 AC 35 ms
53,560 KB
testcase_10 AC 396 ms
101,216 KB
testcase_11 AC 623 ms
127,808 KB
testcase_12 AC 426 ms
102,736 KB
testcase_13 AC 208 ms
79,116 KB
testcase_14 AC 227 ms
79,828 KB
testcase_15 AC 725 ms
132,984 KB
testcase_16 AC 320 ms
88,168 KB
testcase_17 AC 467 ms
106,180 KB
testcase_18 AC 720 ms
140,132 KB
testcase_19 AC 197 ms
78,356 KB
testcase_20 AC 130 ms
76,224 KB
testcase_21 AC 36 ms
53,560 KB
testcase_22 AC 581 ms
114,060 KB
testcase_23 AC 497 ms
111,192 KB
testcase_24 AC 849 ms
143,336 KB
testcase_25 AC 355 ms
93,128 KB
testcase_26 AC 36 ms
53,560 KB
testcase_27 AC 35 ms
53,560 KB
testcase_28 AC 35 ms
53,560 KB
testcase_29 AC 35 ms
53,560 KB
testcase_30 AC 35 ms
53,560 KB
testcase_31 AC 35 ms
53,560 KB
testcase_32 AC 36 ms
53,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 1 << 60

n, x = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in range(n):
  a[i] -= x

if all([x < 0 for x in a]):
  print("-1")
  exit()

cost = - sum(a)
if cost <= 0:
  print("0")
  exit()

dp = {}
dp[0] = 0
ans = INF
for i in range(n):
  if a[i] >= 0:
    continue

  ndp = {}
  for k, v in dp.items():
    ndp[k] = min(ndp.get(k, INF), v)
    nxt = k - a[i]
    if nxt >= cost:
      ans = min(ans, v + b[i])
    else:
      ndp[nxt] = min(ndp.get(nxt, INF), v + b[i])

  dp = ndp

print(ans)
0