#38914: python


111375@goog.ptsh.ntct.edu.tw (陳森凱)

學校 : 南投縣私立普台高級中學
編號 : 253499
來源 : [123.51.150.8]
最後登入時間 :
2024-04-28 22:36:35
h081. 1. 程式交易 -- 2022年1月APCS | From: [123.51.150.8] | 發表日期 : 2024-01-03 20:52

n,d=map(int,input().split())
list1=[int(i) for i in input().split()]
j=1
s=0
x=list1[0]

for i in list1:
    if j==1:
        if i >= x+d:
            s += (i-x)
            j=0
            x=i

    if j==0:
        if i<=x-d:
            j=1
            x=i

print(s)

 
ZeroJudge Forum