Cod sursa(job #12587)

Utilizator Tase_CCapalna Tanase Tase_C Data 4 februarie 2007 14:27:40
Problema Secventa 2 Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.53 kb
var s:array[0..50000] of longint;
    n,k,i,pmax,pmin:longint;
begin
  assign(input,'secv2.in'); reset(input);
  assign(output,'secv2.out'); rewrite(output);
  readln(n,k);
  //facem vectorul
  for i:=1 to n do begin
    read(s[i]); inc(s[i],s[i-1]);
  end;
  pmax:=k;
  //aflam limitele
  for i:=k+1 to n do
    if s[i]>s[pmax] then pmax:=i;
  pmin:=pmax-k;
  for i:=0 to pmin-1 do
    if s[i]<s[pmin] then pmin:=i;
//scriem limitele
  write(pmin+1,' ',pmax,' ',s[pmax]-s[pmin]);
  close(input); close(output);
end.