这道题是贪心的一道题,主要考查一个序列中,上升子序列长度大于等于2的首位和,因为首位差价最大,然后就判断就可以了。
#include<iostream>
using namespace std;
const int N=1e5+10;
const int Inf=0x3f3f3f3f;
int w[N];
int dp[N][2];
int main(void)
{
int n,last=Inf,st=Inf;
long long res=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>w[i];
if(w[i]>last)
{
last=w[i];
}
else
{
res+=last-st;
st=last=w[i];
}
}
res+=last-st;
cout<<res;
}