模型:每次选连续区间将区间内所有数减去一,使得所有数都为0的最少操作次数
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
int a[N],b[N];
int main()
{
int n;
cin>>n;
for (int i = 1; i <= n; i ++ )
{
cin>>a[i];
b[i]=a[i]-a[i-1];
//cout<<b[i]<<" ";
}
int sr=0,st=0;
for (int i = 1; i <= n; i ++ )
{
if(b[i]<0) st+=b[i];
else sr+=b[i];
}
int res=min(abs(st),sr)+sr-abs(st);
cout<<res;
}