fork(3) download
  1.  
  2. // http://c...content-available-to-author-only...s.com/contest/789/problem/C
  3.  
  4. #include<bits/stdc++.h>
  5. #include<unordered_set>
  6. using namespace std;
  7. #define fio ios_base::sync_with_stdio(false)
  8.  
  9. #define ll long long int
  10.  
  11. #define s(x) scanf("%lld",&x)
  12. #define s2(x,y) s(x)+s(y)
  13. #define s3(x,y,z) s(x)+s(y)+s(z)
  14.  
  15. #define p(x) printf("%lld\n",x)
  16. #define p2(x,y) p(x)+p(y)
  17. #define p3(x,y,z) p(x)+p(y)+p(z)
  18. #define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
  19. #define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
  20.  
  21. #define ff first
  22. #define ss second
  23. #define mp(x,y) make_pair(x,y)
  24. #define pll pair<ll,ll>
  25. #define pb push_back
  26.  
  27. // TEMPLATE FOR POLICY BASED DATA STRUCTURES //
  28.  
  29. #include <ext/pb_ds/assoc_container.hpp>
  30. #include <ext/pb_ds/tree_policy.hpp>
  31. using namespace __gnu_pbds;
  32. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
  33.  
  34. // TEMPLATE OVER //
  35.  
  36. ll inf = 1e18;
  37. ll mod = 1e9 + 7 ;
  38. ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
  39.  
  40. ll n;
  41. ll kadane(vector<ll>ar){
  42. ll sum;
  43. sum=ar[0];
  44.  
  45. ll ans=ar[0];
  46. for(ll i=1;i<n-1;i++){
  47. if(sum<0){
  48. sum=ar[i];
  49. }
  50. else sum+=ar[i];
  51. ans=max(ans,sum);
  52. }
  53. return ans;
  54. }
  55.  
  56. int main()
  57. {
  58. // freopen("input.txt","r",stdin);
  59. // freopen("output.txt","w",stdout);
  60. ll t=1;
  61. s(t);
  62.  
  63.  
  64. while(t--){
  65.  
  66. s(n);
  67.  
  68. vector<ll>ar(n+1);
  69. vector<ll>ar1;
  70. vector<ll>ar2;
  71. F(i,0,n-1)cin>>ar[i];
  72. F(i,1,n-1){
  73. ll num = abs(ar[i]-ar[i-1]);
  74. ar1.pb(num); ar2.pb(num);
  75. }
  76.  
  77. for(ll i=0;i<n-1;i+=2)ar1[i]=-ar1[i];
  78. for(ll i=1;i<n-1;i+=2)ar2[i]=-ar2[i];
  79. cout<<max(kadane(ar1),kadane(ar2))<<endl;
  80.  
  81.  
  82. }
  83. }
  84.  
Success #stdin #stdout 0s 16056KB
stdin
2

5
1 4 2 3 1
4
1 5 4 7
stdout
3
6