結果

問題 No.1163 I want to be a high achiever
ユーザー rlangevinrlangevin
提出日時 2023-03-03 12:40:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 642 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 156,568 KB
最終ジャッジ日時 2023-10-18 00:56:35
合計ジャッジ時間 6,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 38 ms
53,428 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 38 ms
53,428 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 38 ms
53,428 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 37 ms
53,428 KB
testcase_27 AC 38 ms
53,428 KB
testcase_28 AC 38 ms
53,428 KB
testcase_29 AC 38 ms
53,428 KB
testcase_30 AC 37 ms
53,428 KB
testcase_31 AC 38 ms
53,428 KB
testcase_32 AC 38 ms
53,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, X = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C, D = [], []
V = 0
for i in range(N):
    if A[i] - X < 0:
        C.append(X - A[i])
        D.append(B[i])
    V += A[i] - X

if V >= 0:
    print(0)
    exit()

V = -V
S = sum(C)
inf = 10 ** 18
pre = [inf] * (S + 1)
pre[0] = 0
for i in range(len(C)):
    dp = [inf] * (S + 1)
    for j in range(S + 1):
        dp[j] = pre[j]
        if j - C[i] >= 0:
            dp[j] = min(dp[j], dp[j - C[i]] + D[i])
    dp, pre = pre, dp

ans = inf
for i in range(V, S + 1):
    ans = min(ans, pre[i])

print(ans) if ans != sum(B) else print(-1)
0