Idea: The situation can only be 2 kinds, two people have been walking to the side, or have a person to fold back, for the latter, enumerate back the location of the line. But be aware that all two directions must be handled.
1 #pragmaComment (linker, "/stack:10240000,10240000")2 3#include <iostream>4#include <cstdio>5#include <algorithm>6#include <cstdlib>7#include <cstring>8#include <map>9#include <queue>Ten#include <deque> One#include <cmath> A#include <vector> -#include <ctime> -#include <cctype> the#include <Set> - - using namespacestd; - + #defineMem0 (a) memset (a, 0, sizeof (a)) - #defineLson L, M, RT << 1 + #defineRson m + 1, R, RT << 1 | 1 A #definedefine_m int m = (L + r) >> 1 at #defineRep (A, b) for (int a = 0; a < b; a++) - #defineRrep (A, b) for (int a = b-1; a >= 0; a--) - #defineAll (a) (a). Begin (), (a). End () - #defineLowbit (x) ((x) & (-(x))) - #defineCONSTRUCTINT4 (name, a, B, C, D) name (int a = 0, int b = 0, int c = 0, int d = 0): A (a), B (b), C (c), D (d) {} - #defineCONSTRUCTINT3 (name, a, B, c) name (int a = 0, int b = 0, int c = 0): A (a), B (b), C (c) {} in #defineConstructInt2 (name, a, b) name (int a = 0, int b = 0): A (a), B (b) {} - #definePC (a) Putchar (a) to #definePS (a) printf ("%s", a) + #definePD (a) printf ("%d", a) - #defineSD (a) scanf ("%d", &a) the *typedefDoubledb; $typedefLong LongLL;Panax Notoginsengtypedef pair<int,int>PII; -typedef multiset<int>MSI; thetypedefSet<int>si; +typedef vector<int>VI; Atypedef map<int,int>Mii; the + Const intdx[8] = {0,1,0, -1,1,1, -1, -1}; - Const intdy[8] = {1,0, -1,0, -1,1,1, -1}; $ Const intMAXN = 1e5 +7; $ Const intMAXM = 1e5 +7; - Const intMAXV = 1e7 +7; - Const intMax_val = 1e6 +7; the Const intMD = 1e9 +7; - Const intINF = 1e9 +7;Wuyi Const DoublePI = ACOs (-1.0); the Const DoubleEPS = 1e-Ten; - Wutemplate<classT> T gcd (t A, T b) {returnb = =0? A:GCD (b, a%b); } - About LL SUM[MAXN], SUM2[MAXN]; $ intA[MAXN]; - intN, p, m, t, X; - - LL work () { ALL ans =0; + intL = max (0, p-t), r = Min (N-1, p +t); the for(inti = l; I < P; i++) { - intPOS1 = p + min (M/2, p-i), Pos2 = min (M + i, p + p-i), pos = max (pos1, Pos2 + t-(P-i)); $pos =min (r, POS); theans = max (ans, sum[pos]-(i-sum[i-1] :0)); the } theans = max (ans, sum[r]-(P-sum[p-1] :0)); the returnans; - } in the intMain () { the //freopen ("In.txt", "R", stdin); About the while(Cin >> N >>p) { thep--; thesum[0] =0; + Rep (i, N) { - SD (A[i]); the if(i) sum[i] = sum[i-1];BayiSum[i] + =A[i]; the } thesum2[0] = A[n-1]; -Rrep (i, N-1) Sum2[n-i-1] = sum2[n-i-2] +A[i]; -CIN >> M >>T; the theLL ans =Work (); thememcpy (Sum, sum2,sizeof(sum)); thep = n-p-1; -Ans =Max (ans, work ()); thecout << ans <<Endl; the } the return 0;94}
View Code
[zoj3627] Simulation bar