結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-04 11:41:01
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,478 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 123,072 KB
最終ジャッジ日時 2023-08-16 13:15:53
合計ジャッジ時間 45,411 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,408 KB
testcase_01 AC 71 ms
71,224 KB
testcase_02 AC 81 ms
76,364 KB
testcase_03 AC 72 ms
71,624 KB
testcase_04 AC 72 ms
71,568 KB
testcase_05 AC 72 ms
71,156 KB
testcase_06 AC 81 ms
76,364 KB
testcase_07 AC 71 ms
71,124 KB
testcase_08 AC 75 ms
75,096 KB
testcase_09 AC 142 ms
77,872 KB
testcase_10 AC 130 ms
77,624 KB
testcase_11 AC 127 ms
77,440 KB
testcase_12 AC 545 ms
87,724 KB
testcase_13 AC 1,627 ms
102,364 KB
testcase_14 AC 359 ms
82,376 KB
testcase_15 AC 209 ms
79,300 KB
testcase_16 AC 268 ms
79,740 KB
testcase_17 AC 310 ms
80,224 KB
testcase_18 AC 70 ms
71,472 KB
testcase_19 AC 71 ms
71,336 KB
testcase_20 AC 71 ms
71,400 KB
testcase_21 AC 122 ms
77,880 KB
testcase_22 AC 118 ms
77,716 KB
testcase_23 AC 123 ms
77,448 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 1,768 ms
104,828 KB
testcase_27 TLE -
testcase_28 AC 796 ms
92,084 KB
testcase_29 AC 814 ms
92,004 KB
testcase_30 AC 72 ms
71,408 KB
testcase_31 AC 71 ms
71,664 KB
testcase_32 AC 116 ms
77,432 KB
testcase_33 AC 127 ms
77,736 KB
testcase_34 AC 123 ms
77,616 KB
testcase_35 AC 1,708 ms
114,956 KB
testcase_36 AC 1,910 ms
116,296 KB
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 AC 1,792 ms
104,908 KB
testcase_41 AC 1,729 ms
110,996 KB
testcase_42 AC 1,694 ms
105,168 KB
testcase_43 TLE -
testcase_44 AC 1,952 ms
103,336 KB
testcase_45 AC 1,685 ms
103,392 KB
testcase_46 AC 789 ms
96,064 KB
testcase_47 AC 801 ms
92,452 KB
testcase_48 AC 797 ms
94,644 KB
testcase_49 AC 872 ms
94,628 KB
testcase_50 AC 786 ms
95,300 KB
testcase_51 AC 815 ms
96,012 KB
testcase_52 AC 646 ms
85,844 KB
testcase_53 AC 653 ms
87,724 KB
testcase_54 AC 153 ms
81,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def maxb(x,y):
    if x>y:return x
    return y
def main1(n,k,pd):
    # 値段高い順にピザを買うかどうか決める。無料チケットを一枚得られる。
    # dp[i,j,s]:i枚目の購入判断が終わったとき、支払い総額がj円で無料チケットがs枚あるときの最大おいしさ
    # dp[i,j]:ある枚目の購入判断が終わったとき、支払い総額がi円で無料チケットがj枚あるときの最大おいしさ
    # チケット貰った瞬間使うのが最適なのでj<2で考えればよい
    pd.sort(key=lambda x:x[0],reverse=True)
    dp0=[-1]*(k+1)
    dp1=[-1]*(k+1)
    dp0[0]=0
    price_list=set([0])
    price_list_add=set()
    for p,d in pd:
        ndp0=[-1]*(k+1)
        ndp1=[-1]*(k+1)
        for i in price_list:
            # チケットなし
            if dp0[i]>=0:
                if i+p<=k:
                    ndp1[i+p]=maxb(ndp1[i+p],dp0[i]+d)
                    price_list_add.add(i+p)
                ndp0[i]=maxb(ndp0[i],dp0[i])
            # チケットあり
            if dp1[i]>=0:
                ndp0[i]=maxb(ndp0[i],dp1[i]+d)
                ndp1[i]=maxb(ndp1[i],dp1[i])
        dp0=ndp0
        dp1=ndp1
        while price_list_add:
            price_list.add(price_list_add.pop())
    return maxb(max(dp0),max(dp1))

if __name__=='__main__':
    n,k=map(int,input().split())
    pd=[list(map(int,input().split())) for _ in range(n)]
    ret1=main1(n,k,pd)
    print(ret1)
0