Official
D - 工場の稼働計画 / Factory Operation Plan Editorial
by
D - 工場の稼働計画 / Factory Operation Plan Editorial
by
sounansya
各日に対し、その日に工場を休止させた・稼働させた場合のそれまでの利益の合計を順に計算していけば良いです。
n, c = map(int, input().split())
a = list(map(int, input().split()))
d0, d1 = 0, a[0]
for v in a[1:]:
d0, d1 = d1, max(d0, d1 - c) + v
print(max(d0, d1))
