Pagini recente » Cod sursa (job #787978) | Cod sursa (job #3128582) | Cod sursa (job #1882859) | Cod sursa (job #2250171) | Cod sursa (job #42832)
Cod sursa(job #42832)
type vect=array[1..16000] of 0..60000;
forafro=1..25000; afro=-1..60000;
var f,g:text;
v,a:vect;
n,t,i,z,j,x:forafro;
ok:boolean;
max:afro;
begin
assign(f,'friends.in'); assign(g,'friends.out');
reset(f); rewrite(g);
readln(f,n); i:=1; ok:=true;
for j:=1 to n do
begin
readln(f,x);
if x>0 then
begin
v[i]:=x;
inc(i);
ok:=true;
end else
if ok=true then
begin
ok:=false;
v[i]:=0;
inc(i);
end;
end;
i:=i-1; a[i]:=v[i];
for t:=i-1 downto 1 do
begin
a[t]:=v[t]; max:=-1;
for z:=t+2 to i do
if not ((t=1)and(z=i)) then
if v[z]>max then max:=v[z];
a[t]:=a[t]+max;
end; max:=-1;
for t:=1 to i do
if max<a[t] then max:=a[t];
write(g,max);
close(f); close(g);
end.