結果

問題 No.3077 Goodstuff Deck Builder(Hard)
ユーザー LyricalMaestro
提出日時 2025-05-24 01:35:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,316 ms / 3,000 ms
コード長 566 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 153,580 KB
最終ジャッジ日時 2025-05-24 01:35:48
合計ジャッジ時間 20,115 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/3077

MIN = -1

def main():
    N, M = map(int, input().split())
    cd = []
    for _ in range(N):
        c, d = map(int, input().split())
        cd.append((c, d))
    
    cd.sort(key=lambda x : x[0])

    dp = [MIN] * (M + 1)
    dp[0] = 0

    for c, d in cd:
        l = M - c
        l //= 2
        for m in reversed(range(l + 1)):
            if dp[m] != MIN:
                w = 2 * m + c
                dp[w] = max(dp[w], dp[m] + d)
    
    print(max(dp))


                




if __name__ == "__main__":
    main()
0