Pagini recente » Cod sursa (job #3269602) | Cod sursa (job #671360) | Cod sursa (job #1690458) | Cod sursa (job #3226260) | Cod sursa (job #34286)
Cod sursa(job #34286)
var v,x,zero:array[-1..100000]of longint;
i,j,n,max:longint;
begin
assign(input,'oo.in');reset(input);
assign(output,'oo.out');rewrite(output);
readln(n);
for i:=1 to n do
read(v[i]);
x[2]:=v[1]+v[2];
for i:=2 to n-1 do
begin
x[i]:=v[i]+v[i-1]+x[i-3];
if x[i-1]>x[i] then
x[i]:=x[i-1];
end;
if x[n-1]>max then
max:=x[n-1];
x:=zero;
x[1]:=v[1]+v[n];
for i:=2 to n-1 do
begin
x[i]:=v[i]+v[i-1]+x[i-3];
if x[i-1]>x[i] then
x[i]:=x[i-1];
end;
if x[n-2]>max then
max:=x[n-2];
x:=zero;
x[1]:=v[n-1]+v[n];
x[0]:=x[1];
for i:=2 to n-1 do
begin
x[i]:=v[i]+v[i-1]+x[i-3];
if x[i-1]>x[i] then
x[i]:=x[i-1];
end;
if x[n-2]>max then
max:=x[n-3];
writeln(max);
close(input);close(output);
end.