Pagini recente » Cod sursa (job #2688250) | Cod sursa (job #2703157) | Cod sursa (job #2560679) | Cod sursa (job #2461770) | Cod sursa (job #34288)
Cod sursa(job #34288)
var v,x,zero:array[-1..100100]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-1]>max then
max:=x[n-1];
writeln(max);
close(input);close(output);
end.