Pagini recente » Cod sursa (job #1904854) | Cod sursa (job #1117281) | Cod sursa (job #1595276) | Cod sursa (job #978345) | Cod sursa (job #40789)
Cod sursa(job #40789)
var f,g:text;
a,s1,s2:array[1..100000] of integer;
maxi,n,i,j,k:longint;
function max(x,y:longint):longint;
var k:longint;begin
if x>y then k:=x
else k:=y; max:=k;
end;
begin
assign(f,'oo.in');
assign(g,'oo.out');
reset(F);
rewrite(G);
readln(f,n);
for i:=1 to n do
read(f,a[i]);
if n=2 then writeln(g,a[1]+a[2])
else
begin
s1[1]:=0;
s1[2]:=a[1]+a[2];
for j:=4 to n-2 do
s1[j+1]:=max(s1[j-2]+a[j]+a[j+1],s1[j-3]+a[j]+a[j+1]);
s2[1]:=0;
s2[2]:=0;
s2[3]:=a[2]+a[3];
for j:=5 to n-1 do
s2[j+1]:=max(s2[j-2]+a[j]+a[j+1],s2[j-3]+a[j]+a[j+1]);
maxi:=0;
for i:=1 to n do
if s1[i]>maxi then maxi:=s1[i];
for i:=1 to n do if s2[i]>maxi then maxi:=s2[i];
writeln(g,maxi);
end; close(F);close(G);
end.