F (x) is a concave function, three points can be, the calculation scheme when the DP. Hang precision is very pit, specify the number of cycles positive solution?
#include <bits/stdc++.h>using namespacestd;Const DoubleEPS = 1e- One;Const intMAXN = 2e5+5;DoubleA[MAXN];DoubleD1[MAXN],D2[MAXN];intN;inlineDoubleCalDoublex) { DoubleA1 =0., A2 =0.; for(inti =1; I <= N; i++) {D1[i]= Max (0., d1[i-1]) +a[i]-x; A1=Max (a1,d1[i]); D2[i]= Min (0., d2[i-1]) +a[i]-x; A2=min (a2,d2[i]); } returnMax (Fabs (A1), fabs (A2));}intMain () {//freopen ("In.txt", "R", stdin);scanf"%d",&N); for(inti =1; I <= N; i++) scanf ("%LF", A +i); DoubleL = -1e4, R =1e4; Doublem1v,m2v; while(r-l>EPS) { DoubleM1 = L + (r-l)/3, M2 = L + (r-l)/3*2; M1V= Cal (M1), M2V =cal (M2); if(ABS (M1V-M2V) <EPS) {L= M1; R =M2; }Else { if(M1v >m2v) {L=M1; }Else{R=M2; }}} printf ("%.15LF", (Cal (L) +cal (R))/2); return 0;}
Codeforces Round #320 (Div. 1) [Bayan Thanks-round] C A weakness and poorness