Cod sursa(job #42832)

Utilizator florin_marius90Florin Marius Popescu florin_marius90 Data 29 martie 2007 15:57:40
Problema Elimin Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.78 kb
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.