結果

問題 No.1163 I want to be a high achiever
ユーザー tktk_snsn
提出日時 2022-05-08 08:55:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 864 ms / 2,000 ms
コード長 651 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 142,080 KB
最終ジャッジ日時 2024-07-07 19:15:23
合計ジャッジ時間 12,399 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
inf = 10 ** 9


N, X = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if all(a < X for a in A):
    print(-1)
    exit()


score = 0
cost = 0
dp = defaultdict(int)
dp[0] = 0

for a, b in zip(A, B):
    if a >= X:
        score += a - X
        cost += b
    else:
        p = X - a
        ndp = defaultdict(int)
        for k, v in dp.items():
            ndp[k] = max(ndp[k], v)
            ndp[k+p] = max(ndp[k+p], v + b)
        dp = ndp


tmp = cost
for k, v in dp.items():
    if k > score:
        continue
    tmp = max(tmp, cost + v)

print(sum(B) - tmp)
0