题目:
分析:稍想一下就是贪心哦。
代码:
#include<bits/stdc++.h>
using namespace std;
int A[100005];
int main()
{
int m;
cin>>m;
for(int i=0;i<m;i++) cin>>A[i];long long ans=A[0];
int now=A[0];
for(int i=1;i<m;i++)
{
if(A[i]==now) ;
if(A[i]>now)
{
ans+=A[i]-now;
now=A[i];
}
else if(A[i]<now)
{
now=A[i];
}
}
cout<<ans;
}