結果

問題 No.561 東京と京都
ユーザー asumo0729asumo0729
提出日時 2020-12-16 14:12:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 586 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 53,572 KB
最終ジャッジ日時 2023-10-20 09:36:26
合計ジャッジ時間 2,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 40 ms
53,352 KB
testcase_03 WA -
testcase_04 AC 39 ms
53,352 KB
testcase_05 AC 39 ms
53,352 KB
testcase_06 WA -
testcase_07 AC 40 ms
53,352 KB
testcase_08 AC 39 ms
53,352 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 40 ms
53,352 KB
testcase_12 AC 40 ms
53,352 KB
testcase_13 WA -
testcase_14 AC 40 ms
53,352 KB
testcase_15 AC 40 ms
53,352 KB
testcase_16 AC 40 ms
53,352 KB
testcase_17 AC 40 ms
53,352 KB
testcase_18 AC 41 ms
53,352 KB
testcase_19 AC 40 ms
53,352 KB
testcase_20 AC 39 ms
53,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
tp=lambda:tuple(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
yp=lambda:print('Yes')
np=lambda:print('No')

n,d=lp()
inf=float('inf')
dp=[[-inf for _ in range(2)]for _ in range(n)]
for i in range(n):
    now=lp()
    if i==0:
        dp[0][0]=now[0]
        dp[0][1]=now[0]-d
    else:
        dp[i][0]=max(dp[i-1][0]+now[0],dp[i-1][1]+now[0]-d)
        dp[i][1]=max(dp[i-1][1]+now[1],dp[i-1][0]+now[1]-d)

print(max(dp[-1][0],dp[-1][1]))
0