Cod sursa(job #393149)

Utilizator philipPhilip philip Data 8 februarie 2010 22:38:37
Problema Subsecventa de suma maxima Scor 80
Compilator fpc Status done
Runda Arhiva educationala Marime 0.5 kb
var bufin:array[1..65000] of byte;
   i,n,x,s,smax,p1,p2:longint;

begin
  assign(input,'ssm.in');
  reset(input);
  settextbuf(input,bufin);
  assign(output,'ssm.out');
  rewrite(output);
  readln(n);
  read(s);
  smax:=-2000000000;
  p1:=1;
  for i:=2 to n do begin
    read(x);
    if x+s>x then s:=s+x else begin
      s:=x;
      p1:=i;
    end;
    if s>smax then begin
      smax:=s;
      p2:=i;
    end;
  end;

  write(smax,' ',p1,' ',p2);

  close(input);
  close(output);
end.