結果
問題 |
No.2232 Miser's Gift
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:24:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 145 ms / 2,000 ms |
コード長 | 682 bytes |
コンパイル時間 | 203 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 77,540 KB |
最終ジャッジ日時 | 2025-03-20 20:26:11 |
合計ジャッジ時間 | 8,536 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 55 |
ソースコード
n, W = map(int, input().split()) items = [tuple(map(int, input().split())) for _ in range(n)] # Initialize DP array for 0-1 knapsack dp = [0] * (W + 1) # Process each item to update the DP array for w_i, v_i in items: for w in range(W, w_i - 1, -1): if dp[w - w_i] + v_i > dp[w]: dp[w] = dp[w - w_i] + v_i # Update the DP array to take cumulative maximum for w in range(1, W + 1): if dp[w] < dp[w - 1]: dp[w] = dp[w - 1] max_original = dp[W] # Calculate the minimum V for each X from 1 to W for X in range(1, W + 1): available = W - X prev_val = dp[available] if available >= 0 else 0 V = max_original - prev_val + 1 print(V)