結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,316 KB
testcase_01 AC 68 ms
71,364 KB
testcase_02 AC 77 ms
76,028 KB
testcase_03 AC 69 ms
71,224 KB
testcase_04 AC 74 ms
71,344 KB
testcase_05 AC 70 ms
71,432 KB
testcase_06 AC 77 ms
76,128 KB
testcase_07 AC 72 ms
71,476 KB
testcase_08 AC 73 ms
71,296 KB
testcase_09 AC 157 ms
77,488 KB
testcase_10 AC 129 ms
77,256 KB
testcase_11 AC 121 ms
77,236 KB
testcase_12 AC 998 ms
145,812 KB
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 #

def main2(n,k,pd):
    pd.sort(key=lambda x:x[0],reverse=True)
    dp0={}
    dp1={}
    dp0[0]=0
    for _,(p,d) in enumerate(pd):
        ndp0={}
        ndp1={}
        for i in dp0:
            # チケットなし
            if i+p<=k:
                if i+p in ndp1:
                    ndp1[i+p]=max(ndp1[i+p],dp0[i]+d)
                else:
                    ndp1[i+p]=dp0[i]+d
            if i in ndp0:
                ndp0[i]=max(ndp0[i],dp0[i])
            else:
                ndp0[i]=dp0[i]
        for i in dp1:
            # チケットあり
            if i in ndp0:
                ndp0[i]=max(ndp0[i],dp1[i]+d)
            else:
                ndp0[i]=dp1[i]+d
            if i in ndp1:
                ndp1[i]=max(ndp1[i],dp1[i])
            else:
                ndp1[i]=dp1[i]
        dp0=ndp0
        dp1=ndp1
    return max(max(dp0.values()),max(dp1.values()))

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