結果

問題 No.561 東京と京都
ユーザー URechaRecha
提出日時 2019-09-03 20:41:10
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 731 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-12-24 14:54:35
合計ジャッジ時間 1,535 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 4
other RE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

def tokyo_and_kyoto(inp):
    inp_l = inp.split("\n")
    n, d = map(int,inp_l.pop(0).split())
    heap = [[[0],0]]
    for _ in range(n):
        l = len(heap)
        a, b = map(int, inp_l.pop(0).split())
        for _ in range(l):
            path, money =heap.pop(0)
            if path[-1] == 0:
                heap.append([path+[0],money+a])
                heap.append([path+[1],money+b-d])
            else:
                heap.append([path+[0],money+a-d])
                heap.append([path+[1],money+b])
    heap.sort(key= lambda x:x[1],reverse=True)
    return heap[0][1]

if __name__ == "__main__":
    a =" "
    inp = ""
    while " " in a:
        a = input()
        inp += a + "\n"
    print(tokyo_and_kyoto(inp))
0