The classic demolition absolute value
Subject to the effect
$ $ A given n-th order of the sequence, each sequence allowing movement of the cycle. - recording $ I $ sequence tail elements $ x $, $ i + 1 $ sequence header element is $ y $, is defined which is connected earnings $ | xy | * i $, seeking $ n-$ sequence attached to the largest revenue .
$ \ Sum n \ 10 ^ 6 $
Topic analysis
Do less classic dp
Consider how to handle an absolute value of: the absolute value discussed separately by category in both cases nothing more than $ x * iy * i $ or $ y * ix * i $, and both are of different signs, the problem is equivalent to turn $ \ $ of max.
Thus do not control the relative size of the two elements, the elements need only record a_v $ $ a $ \ max \ {f_ {a_v} -a_v * i \} $ and $ \ max \ {f_ {a_v} + a_v * i \ } $ apart. both transfer time.
What is the sense in the following figure
1 #include<bits/stdc++.h> 2 typedef long long ll; 3 const ll INF = 1ll<<60; 4 const int maxn = 1000035; 5 6 int T,n,len[maxn],id[maxn]; 7 ll f[maxn],ans,pre,suf; 8 std::vector<int> a[maxn]; 9 10 int read() 11 { 12 char ch = getchar(); 13 int num = 0, fl = 1; 14 for (; !isdigit(ch); ch=getchar()) 15 if (ch=='-') fl = -1; 16 for (; isdigit(ch); ch=getchar()) 17 num = (num<<1)+(num<<3)+ch-48; 18 return num*fl; 19 } 20 int main() 21 { 22 for (T=read(); T; --T) 23 { 24 n = read(), id[0] = 1; 25 for (int i=1; i<=n; i++) 26 { 27 a[i].clear(), len[i] = read(), id[i] = id[i-1]+len[i-1]; 28 for (int j=1; j<=len[i]; j++) 29 a[i].push_back(read()); 30 } 31 ans = pre = suf = 0; 32 for (int i=1; i<=n; i++) 33 { 34 ll nxtp = -INF, nxts = 0, val = 0; 35 for (int j=0,mx=a[i].size(),lst; j<mx; j++) 36 { 37 lst = j?(j-1):a[i].size()-1; 38 val = std::max(pre+1ll*a[i][j]*(i-1), suf-1ll*a[i][j]*(i-1)); 39 ans = std::max(ans, val); 40 nxtp = std::max(nxtp, val-1ll*a[i][lst]*i); 41 nxts = std::max(nxts, val+1ll*a[i][lst]*i); 42 } 43 pre = nxtp, suf = nxts; 44 } 45 printf("%lld\n",ans); 46 } 47 return 0; 48 }
END