Cod sursa(job #268877)

Utilizator MBlueGheorghevici Mihai MBlue Data 1 martie 2009 22:52:16
Problema Subsecventa de suma maxima Scor 95
Compilator fpc Status done
Runda Arhiva educationala Marime 1.1 kb
type elemnt = record
              val : longint;
              nrel : longint;
              besti : longint;
              end;
var fin,fout : text;
    el,ultimu,maxim : elemnt;
    N,i,j : longint;
procedure max(a,b : longint);
begin
     if a > b then begin
                   el.besti := a;
                   el.nrel := ultimu.nrel +1;
                   end
              else begin
                   el.besti := b;
                   el.nrel := 1;
                   end;
end;
begin
     assign(fin,'ssm.in');
     reset(fin);
     assign(fout,'ssm.out');
     rewrite(fout);
     read(fin,N);
     read(fin,el.val);
     el.besti := el.val;
     el.nrel := 1;
     maxim := el;
     j := i;
     for i := 2 to n do begin
         read(fin,el.val);
         max(ultimu.besti + el.val,el.val);
         if maxim.besti < el.besti then begin
            maxim := el;
            j := i;
         end;
         if el.besti = 0 then el.nrel := 0;
         ultimu := el;
     end;
     close(fin);
     write(fout,maxim.besti,' ',j - maxim.nrel +1,' ',j);
     close(fout);
end.