結果

問題 No.3329 Only the Rightest Choice is Right!!!
コンテスト
ユーザー iastm
提出日時 2025-11-01 16:40:05
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 849 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 82,668 KB
実行使用メモリ 528,776 KB
最終ジャッジ日時 2025-11-01 16:40:26
合計ジャッジ時間 15,215 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44 WA * 29 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

N, X = (int(x) for x in input().split())
V = [int(x) for x in input().split()]
W = [int(x) for x in input().split()]

dp = [[(-1, -1, -1)] * (X + 1)]
dp[0][0] = (0, -1, -1)
for i in range(N - 1, -1, -1):
    ndp = dp[-1][:]
    for w in range(X - W[i], -1, -1):
        if dp[-1][w][0] == -1:
            continue
        if (
            ndp[w + W[i]][0] == -1
            or dp[-1][w][0] + V[i] > ndp[w + W[i]][0]
        ):
            ndp[w + W[i]] = (dp[-1][w][0] + V[i], i, dp[-1][w][1])
    dp.append(ndp)

result = []
for w in range(X, -1, -1):
    if dp[-1][w][0] == -1:
        continue
    target = dp[-1][w][1]
    while target != -1:
        if dp[-1][w][1] == target:
            result.append(target + 1)
            target = dp[-1][w][2]
            w -= W[dp[-1][w][1]]
        dp.pop()
    break

print(len(result))
print(*result)
0