Cod sursa(job #34286)

Utilizator CezarMocanCezar Mocan CezarMocan Data 20 martie 2007 16:09:31
Problema Oo Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.88 kb
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.