Cod sursa(job #38623)

Utilizator floringh06Florin Ghesu floringh06 Data 25 martie 2007 22:20:27
Problema Secventa 2 Scor 80
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.55 kb

var fi,fo:text;
    i,j,n,k:word;
    vl,max,indi,indj:longint;
    s:array[0..50002] of longint;


begin
 assign(fi,'secv2.in'); reset(fi);
 assign(fo,'secv2.out'); rewrite(fo);
 readln(fi,n,k);
 for i:=1 to n do
  begin
   read(fi,vl);
   s[i]:=s[i-1]+vl;
  end;
 if k=0 then
  begin
   writeln(fo,0);
   close(fo);
  end;
 max:=-maxlongint;
 for i:=k to n do
  for j:=0 to i-k do
   if s[i]-s[j] > max then
    begin
     max:=s[i]-s[j];
     indi:=i;
     indj:=j+1;
    end;
 writeln(fo,indj,' ',indi,' ',max);
close(fo);
end.