Pagini recente » Cod sursa (job #2554346) | Cod sursa (job #327927) | Cod sursa (job #2827952) | Cod sursa (job #1740491) | Cod sursa (job #34290)
Cod sursa(job #34290)
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-3]>max then
max:=x[n-3];
writeln(max);
close(input);close(output);
end.