結果

問題 No.1163 I want to be a high achiever
ユーザー qib
提出日時 2023-03-02 20:47:11
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 514 ms / 2,000 ms
+ 676µs
コード長 562 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 237 ms
コンパイル使用メモリ 95,844 KB
実行使用メモリ 151,424 KB
最終ジャッジ日時 2026-08-29 15:18:24
合計ジャッジ時間 9,274 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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