P4552 [Poetize6] IncDec Sequence

点击查看代码
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N=1e5+10;
LL a[N],b[N];
int n;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);

    cin>>n;

    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(i>1) b[i]=a[i]-a[i-1];
    }

    LL p=0,q=0;
    for(int i=2;i<=n;i++){
        if(b[i]>0) p+=b[i];
        else q-=b[i];
    }

    cout<<max(p,q)<<endl<<abs(p-q)+1<<endl;

    return 0;
    
}
posted @ 2026-02-09 23:01  AnoSky  阅读(3)  评论(0)    收藏  举报