結果

問題 No.1163 I want to be a high achiever
ユーザー rin204
提出日時 2022-03-23 15:23:45
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 488 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 154 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 61,312 KB
最終ジャッジ日時 2026-04-28 00:25:30
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n, x = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ab = [(a, b) for a, b in zip(A, B)]
ab.sort(reverse = True)
ans = 0
tot = 0
lst = []
for a, b in ab:
    if a >= x:
        ans += b
        tot += a - x
    else:
        lst.append((x - a, b))
if ans == 0:
    print(-1)
    exit()
dp = [0] * (tot + 1)
for a, b in lst:
    for i in range(tot, a - 1, -1):
        dp[i] = max(dp[i], dp[i - a] + b)
ans += dp[-1]
print(sum(B) - ans)
0