1 /* 2 CF789C. Functions again 3 http://codeforces.com/contest/789/problem/C 4 水题 5 题意:求数组中的连续和的最大值 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath> 11 #include <vector> 12 #include <queue> 13 //#define test 14 using namespace std; 15 const int Nmax=1e6; 16 int num[Nmax]; 17 int num1[Nmax]; 18 int num2[Nmax]; 19 long long ans1,ans2; 20 int main() 21 { 22 #ifdef test 23 #endif 24 int n; 25 //freopen("test.in","r",stdin); 26 scanf("%d",&n); 27 for(int i=1;i<=n;i++) 28 { 29 scanf("%d",&num[i]); 30 } 31 for(int i=1;i<n;i++) 32 num[i]=abs(num[i]-num[i+1]); 33 for(int i=1;i<n;i++) 34 { 35 if(i&1) 36 num1[i]=num[i],num2[i]=-num[i]; 37 else 38 num1[i]=-num[i],num2[i]=num[i]; 39 } 40 //for(int i=1;i<n;i++) 41 //printf("%d %d ",num1[i],num2[i]); 42 ans1=ans2=0LL; 43 long long tmp=0LL; 44 for(int i=1;i<n;i++) 45 { 46 tmp+=1LL*num1[i]; 47 if(tmp>ans1) 48 ans1=tmp; 49 if(tmp<0LL) 50 tmp=0LL; 51 } 52 tmp=0; 53 for(int i=1;i<n;i++) 54 { 55 tmp+=1LL*num2[i]; 56 //printf("i:%d tmp:%d ",i,tmp); 57 if(tmp>ans2) 58 ans2=tmp; 59 if(tmp<0LL) 60 tmp=0LL; 61 } 62 printf("%lld ",max(ans1,ans2)); 63 return 0; 64 }