#33813: 解題報告


s11104220@school.saihs.edu.tw (施同學)

學校 : 臺北市立松山高級工農職業學校
編號 : 221254
來源 : [118.165.9.231]
最後登入時間 :
2024-05-08 19:46:59
h081. 1. 程式交易 -- 2022年1月APCS | From: [123.193.213.137] | 發表日期 : 2023-02-05 04:49

我的答案
ns=input().split(' ')
price=input().split(' ')
ans=0
has=True
haspos=0
for i in range(1,len(price)):
    if has and (int(price[i])>=int(price[haspos])+int(ns[1])):
        ans+=int(price[i])-int(price[haspos])
        haspos=i
        has=False
    elif has==False and (int(price[i])<=int(price[haspos])-int(ns[1])):
        haspos=i
        has=True
print(ans)
 
ZeroJudge Forum