提交时间:2023-11-18 08:23:10
运行 ID: 110959
#include<bits/stdc++.h> using namespace std; int price[1001],n,cost,ans; int main() { cin>>n; for(int i=1;i<=n;i++) {cin>>price[i];} for(int i=1;i<=n;i++) { if(cost>0) { if(i==n) {ans+=price[i]-cost;break;} if(price[i+1]<price[i]) {ans+=price[i]-cost;cost=0;} } if(price[i+1]>=price[i]&&!cost) cost=price[i]; } cout<<ans; }