結果

問題 No.1163 I want to be a high achiever
ユーザー tktk_snsntktk_snsn
提出日時 2022-05-08 08:55:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 937 ms / 2,000 ms
コード長 651 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 146,508 KB
最終ジャッジ日時 2023-09-22 02:27:21
合計ジャッジ時間 16,079 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
77,924 KB
testcase_01 AC 102 ms
71,732 KB
testcase_02 AC 102 ms
71,428 KB
testcase_03 AC 112 ms
77,364 KB
testcase_04 AC 474 ms
103,064 KB
testcase_05 AC 722 ms
127,344 KB
testcase_06 AC 274 ms
84,076 KB
testcase_07 AC 852 ms
142,288 KB
testcase_08 AC 884 ms
143,776 KB
testcase_09 AC 213 ms
78,716 KB
testcase_10 AC 499 ms
106,156 KB
testcase_11 AC 702 ms
129,252 KB
testcase_12 AC 504 ms
107,868 KB
testcase_13 AC 316 ms
87,772 KB
testcase_14 AC 328 ms
88,288 KB
testcase_15 AC 878 ms
132,240 KB
testcase_16 AC 406 ms
97,212 KB
testcase_17 AC 543 ms
109,268 KB
testcase_18 AC 906 ms
142,280 KB
testcase_19 AC 294 ms
83,728 KB
testcase_20 AC 265 ms
81,164 KB
testcase_21 AC 186 ms
78,740 KB
testcase_22 AC 647 ms
119,556 KB
testcase_23 AC 586 ms
114,792 KB
testcase_24 AC 937 ms
146,508 KB
testcase_25 AC 450 ms
100,292 KB
testcase_26 AC 102 ms
71,876 KB
testcase_27 AC 101 ms
71,560 KB
testcase_28 AC 102 ms
71,768 KB
testcase_29 AC 103 ms
71,824 KB
testcase_30 AC 100 ms
71,744 KB
testcase_31 AC 105 ms
71,628 KB
testcase_32 AC 105 ms
71,560 KB
権限があれば一括ダウンロードができます

ソースコード

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