AcWing 100. IncDec序列
原题链接
中等
作者:
melody
,
2019-05-06 08:32:10
,
所有人可见
,
阅读 1076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nn=1e5+100;
int n;
ll a[nn],b[nn];
ll p,q;
inline ll read()
{
ll x=0,f=1; char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) a[i]=read();
for(int i=2;i<=n;++i)
{
b[i]=a[i]-a[i-1];
if(b[i]>=0) p+=b[i];
else q+=b[i];
}
q=llabs(q);
cout<<max(p,q)<<endl;
cout<<llabs(p-q)+1<<endl;
return 0;
}