結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー mkawa2mkawa2
提出日時 2019-12-25 15:17:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 502 ms / 2,000 ms
コード長 1,221 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 81,576 KB
実行使用メモリ 77,040 KB
最終ジャッジ日時 2023-10-25 07:32:28
合計ジャッジ時間 14,266 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,360 KB
testcase_01 AC 41 ms
53,360 KB
testcase_02 AC 53 ms
63,536 KB
testcase_03 AC 44 ms
58,976 KB
testcase_04 AC 41 ms
53,360 KB
testcase_05 AC 41 ms
53,360 KB
testcase_06 AC 49 ms
61,344 KB
testcase_07 AC 41 ms
53,360 KB
testcase_08 AC 48 ms
61,332 KB
testcase_09 AC 84 ms
72,752 KB
testcase_10 AC 69 ms
68,028 KB
testcase_11 AC 77 ms
72,812 KB
testcase_12 AC 167 ms
76,892 KB
testcase_13 AC 412 ms
76,924 KB
testcase_14 AC 130 ms
76,528 KB
testcase_15 AC 120 ms
76,084 KB
testcase_16 AC 148 ms
76,996 KB
testcase_17 AC 182 ms
76,896 KB
testcase_18 AC 41 ms
53,360 KB
testcase_19 AC 40 ms
53,360 KB
testcase_20 AC 40 ms
53,360 KB
testcase_21 AC 64 ms
65,964 KB
testcase_22 AC 66 ms
68,040 KB
testcase_23 AC 65 ms
68,032 KB
testcase_24 AC 411 ms
76,912 KB
testcase_25 AC 470 ms
76,900 KB
testcase_26 AC 456 ms
77,004 KB
testcase_27 AC 435 ms
76,912 KB
testcase_28 AC 370 ms
76,868 KB
testcase_29 AC 396 ms
76,892 KB
testcase_30 AC 40 ms
53,360 KB
testcase_31 AC 41 ms
53,360 KB
testcase_32 AC 65 ms
67,964 KB
testcase_33 AC 69 ms
67,964 KB
testcase_34 AC 64 ms
65,956 KB
testcase_35 AC 406 ms
76,844 KB
testcase_36 AC 365 ms
77,040 KB
testcase_37 AC 391 ms
76,856 KB
testcase_38 AC 482 ms
77,008 KB
testcase_39 AC 475 ms
76,848 KB
testcase_40 AC 404 ms
76,868 KB
testcase_41 AC 444 ms
76,976 KB
testcase_42 AC 373 ms
76,988 KB
testcase_43 AC 469 ms
77,008 KB
testcase_44 AC 374 ms
76,892 KB
testcase_45 AC 502 ms
76,988 KB
testcase_46 AC 389 ms
76,976 KB
testcase_47 AC 399 ms
76,844 KB
testcase_48 AC 350 ms
76,972 KB
testcase_49 AC 387 ms
76,928 KB
testcase_50 AC 348 ms
76,892 KB
testcase_51 AC 374 ms
76,944 KB
testcase_52 AC 246 ms
76,824 KB
testcase_53 AC 265 ms
76,836 KB
testcase_54 AC 193 ms
76,792 KB
権限があれば一括ダウンロードができます

ソースコード

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