BZOJ 3043: IncDec Sequence 差分 + 思维

Code: 

#include <bits/stdc++.h>
#define setIO(s) freopen(s".in","r",stdin) 
#define ll long long  
#define maxn 100034
using namespace std; 
ll a[maxn];   
int main() {
   //  setIO("input");    
    int n; 
    scanf("%d",&n); 
    for(int i=1;i<=n;++i) scanf("%lld",&a[i]);     
    ll pos=0,neg=0; 
    for(int i=n;i>1;--i) {
        if(a[i-1] > a[i]) pos+=a[i-1]-a[i]; 
        else neg+=a[i]-a[i-1]; 
    } 
    printf("%lld\n%lld",max(pos, neg), abs(pos-neg)+1);  
    return 0; 
}

  

posted @ 2019-07-25 14:57  EM-LGH  阅读(119)  评论(0编辑  收藏  举报