洛谷 P4552 [Poetize6] IncDec Sequence

牛客 50929 IncDec Sequence

#include<cstdio>
#include<algorithm>
using namespace std;
long long positive,negative;
int main() {
    int n,x,y,last;
    scanf("%d%d",&n,&last),n--;
    while(n--) {//从第二个数开始
        scanf("%d",&y);
        x=y,y-=last,last=x;//last记录前一个数,y是差分后的数
        if (y>0) positive+=y;
        else negative-=y;
    }
    printf("%lld\n%lld",max(positive,negative),abs(positive-negative)+1);
}

网上讲解很多,在这里就不赘述了qwq