結果
| 問題 |
No.3077 Goodstuff Deck Builder(Hard)
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2025-03-25 07:11:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,844 ms / 3,000 ms |
| コード長 | 708 bytes |
| コンパイル時間 | 269 ms |
| コンパイル使用メモリ | 82,452 KB |
| 実行使用メモリ | 275,500 KB |
| 最終ジャッジ日時 | 2025-03-27 13:02:19 |
| 合計ジャッジ時間 | 49,775 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 57 |
ソースコード
from collections import deque
def main():
N, M = map(int, input().split())
hand = []
for _ in range(N):
C, D = map(int, input().split())
hand.append((C, D))
# Sort the hand by the first value in descending order
hand.sort(reverse=True, key=lambda x: (x[0], x[1]))
dp = [0] * (M + 1)
dp[M] = 0
for C, D in hand:
dp_next = [0] * (M + 1)
for i in range(C, M + 1):
if dp[i] + D > dp_next[(i - C) // 2]:
dp_next[(i - C) // 2] = dp[i] + D
for i in range(0, M + 1):
dp_next[i] = max(dp_next[i], dp[i])
dp = dp_next
ans = max(dp)
print(ans)
if __name__ == "__main__":
main()