AcWing 100. 增减序列
原题链接
中等
作者:
Object_
,
2020-04-29 17:34:36
,
所有人可见
,
阅读 555
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
const int MAXN=2e5;
ll absA(ll a){
if(a<0)return -a;
return a;
}
ll a[MAXN],b[MAXN];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
ll p=0,q=0;
for(int i=2;i<=n;i++){
b[i]=a[i]-a[i-1];
if(b[i]>0){
p+=b[i];
}
if(b[i]<0){
q+=absA(b[i]);
}
}
ll ans1=max(p,q);
ll ans2=absA(p-q)+1;
cout<<ans1<<endl;
cout<<ans2<<endl;
return 0;
}