結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー mkawa2mkawa2
提出日時 2019-12-25 15:16:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,221 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 11,804 KB
実行使用メモリ 10,612 KB
最終ジャッジ日時 2023-10-25 07:31:26
合計ジャッジ時間 5,208 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,140 KB
testcase_01 AC 30 ms
10,140 KB
testcase_02 AC 29 ms
10,148 KB
testcase_03 AC 30 ms
10,140 KB
testcase_04 AC 29 ms
10,140 KB
testcase_05 AC 29 ms
10,140 KB
testcase_06 AC 30 ms
10,148 KB
testcase_07 AC 29 ms
10,140 KB
testcase_08 AC 30 ms
10,144 KB
testcase_09 AC 187 ms
10,272 KB
testcase_10 AC 119 ms
10,268 KB
testcase_11 AC 103 ms
10,220 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

# 食べるピザを確定させたとき、値段の高い順に有料、無料を繰り返すのが最適
# よって、値段の高い順にピザを見ていって、次が有料→次が無料→次が有料→次が無料と
# 表を交互に遷移させる
def main():
    n, k = MI()
    hp = []
    for _ in range(n):
        p, d = MI()
        heappush(hp, [-p, d])
    # dp0[i] i円で得られる最大のおいしさ(次のピザ有料)
    # dp1[i] i円で得られる最大のおいしさ(次のピザ無料)
    dp0 = [-1] * (k + 1)
    dp1 = [-1] * (k + 1)
    dp0[0] = 0
    while hp:
        p, d = heappop(hp)
        p = -p
        for i in range(k, -1, -1):
            if i + p <= k and dp0[i] != -1:
                dp1[i + p] = max(dp1[i + p], dp0[i] + d)
            if dp1[i] != -1:
                dp0[i] = max(dp0[i], dp1[i] + d)
    print(max(max(dp0), max(dp1)))

main()
0