Pagini recente » Cod sursa (job #3173057) | Cod sursa (job #1914202) | Cod sursa (job #1457910) | Cod sursa (job #2977296) | Cod sursa (job #34284)
Cod sursa(job #34284)
var v,x,zero:array[-1..100000]of byte;
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:=3 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-2 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.