Question link: Click the open link
Question:
First line n m
N vectors
The first digit in N rows below indicates the size of the vector, and the following U digit gives the Vector
M digits in the last row
Concatenates the preceding vector.
Obtain a large sequence, and obtain the maximum sub-segment and
First, the maximum child segment sum of each vector is pre-processed, and the left is continuous and the right is continuous. The sum of all numbers
Then DP ..
# Include <cstdio> # include <iostream> # include <algorithm> # include <string. h ># include <vector> using namespace STD; const long INF = 1e18; # define ll long # define n 250010 inline ll max (ll n, ll X []) {ll ans = x [0], sum = x [0]; for (ll I = 1; I <n; I ++) {sum + = x [I]; ans = max (ANS, sum);} return ans;} vector <ll> G [N]; ll n, m; ll l [N], R [N], COP [N], sum [N], W [N]; ll work (ll x) {ll ans = G [x] [0], sum = 0; For (ll I = 0; I <G [X]. size (); I ++) {If (sum + G [x] [I]> = 0) {sum + = G [x] [I]; ans = max (ANS, sum);} else sum = 0; ans = max (ANS, G [x] [I]);} return ans;} void input () {for (ll I = 1; I <= N; I ++) {G [I]. clear (); sum [I] = 0; ll U, V; scanf ("% i64d", & U); While (u --) {scanf ("% i64d ", & V); G [I]. push_back (V); sum [I] + = V;} For (ll j = 0; j <G [I]. size (); j ++) COP [J] = G [I] [J]; L [I] = max (LL) g [I]. size (), COP); For (LL J = 0; j <G [I]. size (); j ++) COP [G [I]. size ()-J-1] = G [I] [J]; R [I] = max (LL) g [I]. size (), COP); W [I] = work (I) ;}} ll DP [250010] [2]; int main () {ll U; while (~ Scanf ("% i64d % i64d", & N, & M) {input (); LL ans =-INF; DP [0] [0] = DP [0] [1] =-INF; For (ll I = 1; I <= m; I ++) {scanf ("% i64d", & U); DP [I] [0] = DP [I-1] [1] + max (sum [u], L [u]); DP [I] [0] = max (DP [I] [0], max (sum [u], L [u]); DP [I] [1] = DP [I-1] [1] + sum [u]; DP [I] [1] = max (DP [I] [1], sum [u]); DP [I] [1] = max (DP [I] [1], R [u]); ans = max (ANS, DP [I] [0]); ans = max (ANS, DP [I] [1]); ans = max (ANS, W [u]);} cout <ans <Endl;} return 0 ;} /* 3 48-10 1 9-10 2-10-97 3-10-10-6 3-7 01-31 3 2 3 */