Cod sursa(job #186985)

Utilizator AndreiDDiaconeasa Andrei AndreiD Data 29 aprilie 2008 17:13:13
Problema Oo Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.12 kb
var n,max:longint;
o,oo0,oo1,oo2:array[0..100000] of longint;
f,g:text;
begin
assign(f,'oo.in');reset(f);
assign(g,'oo.out');rewrite(g);
read(f,n);
for i:=0 to n-1 do read(f,o[i]);
oo0[1]:=o[0]+o[1];
oo0[2]:=0;
oo0[3]:=0;
oo0[4]:=oo0[1]+o[3]+o[4];
oo1[1]:=0;
oo1[2]:=o[1]+o[2];
oo1[3]:=o[2]+o[3];
oo1[4]:=o[3]+o[4];
oo2[0]:=o[n-1]+o[0];
oo2[1]:=0;
oo2[2]:=0;
oo2[3]:=oo2[0]+o[2]+o[3];
oo2[4]:=oo2[0]+o[3]+o[4];
for i:=5 to n-1 do begin
    oo0[i]:=oo0[i-3];
    if oo0[i-4]>oo0[i] then oo0[i]:=oo0[i-4];
    if oo0[i-5]>oo0[i] then oo0[i]:=oo0[i-5];
    oo0[i]:=oo0[i]+o[i-1]+o[i];
    oo1[i]:=oo1[i-3];
    if oo1[i-4]>oo1[i] then oo1[i]:=oo1[i-4];
    if oo1[i-5]>oo1[i] then oo0[i]:=oo1[i-5];
    oo1[i]:=oo1[i]+o[i-1]+o[i];
    oo2[i]:=oo2[i-3];
    if oo2[i-4]>oo2[i] then oo2[i]:=oo2[i-5];
    if oo2[i-5]>oo2[i] then oo2[i]:=oo2[i-4];
    oo2[i]:=oo2[i]+o[i-1]+o[i];
                 end;
oo0[n-1]:=0;
oo2[n-1]:=0;
oo2[n-2]:=0;
for i:=0 to n-1 do begin
    if oo0[i]>max then max:=oo0[i];
    if oo1[i]>max then max:=oo1[i];
    if oo2[i]>max then max:=oo2[i];
write(g,max);
close(f);
close(g);
end.