Cod sursa(job #273115)

Utilizator FllorynMitu Florin Danut Flloryn Data 8 martie 2009 10:21:52
Problema Subsecventa de suma maxima Scor 85
Compilator fpc Status done
Runda Arhiva educationala Marime 0.75 kb
program pascal;
var f,g:text; s:array[0..6000000] of longint; best,max,poz1,i,a,n,poz2,l:longint;

  procedure citire;
  begin
  assign(f,'ssm.in'); reset(f);
  assign(g,'ssm.out'); rewrite(g);
  readln(f,n);
  read(f,a); s[1]:=a; best:=a; max:=a; poz1:=1; poz2:=1; l:=1;

  for i:=2 to n do
     begin
     read(f,a);
     s[i]:=s[i-1]+a;
     if s[i]-best>max then
              begin
              max:=s[i]-best;
              poz2:=i;
              end;
     if (s[i]-best=max) and (i-poz1+1<l) then    poz2:=i;
     if s[i]<best then begin
                       best:=s[i];
                       poz1:=i;
                       end;
     end;

  write(g,max,' ',poz1+1,' ',poz2);
  close(f);
  close(g);
  end;

begin
citire;
end.