标签:amp lse highlight ons scan input bsp c++ code
求一个最长子段和就完了,可以出T1?
code:
#include <bits/stdc++.h> #define N 100006 #define ll long long #define setIO(s) freopen(s".in","r",stdin) using namespace std; ll a[N],A[N],B[N],f[N],g[N]; int main() { ll mx=0; int i,j,n; // setIO("input"); scanf("%d",&n); for(i=1;i<=n;++i) scanf("%lld",&a[i]); for(i=1;i<n;++i) { if(i%2==1) A[i]=abs(a[i]-a[i+1]), B[i]=-A[i]; else A[i]=-abs(a[i]-a[i+1]), B[i]=-A[i]; } f[1]=A[1], g[1]=B[1]; mx=max(A[1], B[1]); for(i=2;i<n;++i) { f[i]=max(f[i-1],0*1ll)+A[i]; g[i]=max(g[i-1],0*1ll)+B[i]; mx=max(mx, f[i]); mx=max(mx, g[i]); } printf("%lld\n",mx); return 0; }
标签:amp lse highlight ons scan input bsp c++ code
原文地址:https://www.cnblogs.com/guangheli/p/11619127.html