白书上的题目
这里唯一要说一下的就是,二分答案不难想到,怎么构造答案的合理性非常值得注意
var a,b,d:array[..] of longint;
n,l,r,m,ans,i:longint; function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; function check(k:longint):boolean;
var x,y,i:longint;
begin
x:=a[];
y:=k-a[];
b[]:=x;
d[]:=;
for i:= to n do
if i mod = then
begin
d[i]:=min(y-d[i-],a[i]);
b[i]:=a[i]-d[i];
end
else begin
b[i]:=min(x-b[i-],a[i]);
d[i]:=a[i]-b[i];
end;
if b[n]= then exit(true) else exit(false);
end; begin
readln(n);
for i:= to n do
read(a[i]);
if n= then
begin
writeln(a[]);
halt;
end;
a[n+]:=a[];
for i:= to n do
l:=max(l,a[i]+a[i+]);
if n mod = then writeln(l)
else begin
for i:= to n do
r:=max(r,a[i]*);
ans:=r;
while l<=r do
begin
m:=(l+r) shr ;
if check(m) then
begin
ans:=m;
r:=m-;
end
else l:=m+;
end;
writeln(ans);
end;
end.