Cod sursa(job #582805)

Utilizator ion_calimanUAIC Ion Caliman ion_caliman Data 15 aprilie 2011 22:29:43
Problema Secventa 2 Scor 40
Compilator fpc Status done
Runda brasov_final_round Marime 0.83 kb
var     a,sum:array[0..6000000] of longint;
        buf:array[1..100000000] of char;
        n,i,j,min,s,t,x,y,best,k:longint;
        sir:string;
        f,g:text;

begin
  assign(f,'secv2.in');
  assign(g,'secv2.out');
  reset(f);
  settextbuf(f,buf);
  rewrite(g);
  readln(f,n,k);
  s:=-1000000000;
  y:=0;
  for i:=1 to n do
    begin
      read(f,a[i]);
      if a[i]>0 then t:=-1;
      if a[i]>s then begin s:=a[i]; x:=i; end;
      a[i]:=a[i]+a[i-1];
    end;

  if t=-1 then
  begin
    s:=-1000000000;
    min:=1000000000;
    x:=1;
    for i:=1 to n do
      begin
        best:=a[i]-min;
        if min>a[i] then begin t:=i+1; min:=a[i]; end;
        if (s<best)and(i-t+1>=k) then begin s:=best; y:=i; x:=t; end;
      end;
  end;
  if y=0 then y:=x;
  write(g,x,' ',y,' ',s);
  close(g);
end.