Cod sursa(job #1111256)

Utilizator atatomirTatomir Alex atatomir Data 18 februarie 2014 19:09:47
Problema Secventa Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.72 kb
type numar = record
       i,v:smallint;
     end;
var n,k,i,j,t,x:longint;
    bufin:array[1..65000]of byte;
    max,maxi:longint;
    v:array[1..500000]of numar;

begin
  assign(input,'secventa.in'); reset(input);
  assign(output,'secventa.out'); rewrite(output);
  settextbuf(input,bufin);

  readln(n,k);
  i := 1; j := 0;
  max := -1;

  for t := 1 to n  do
  begin
    read(x);
    if (i <= j) and (v[i].i <= t -k) then inc(i);
    while (i <= j) and (v[j].v > x) do dec(j);
    inc(j); v[j].i := t; v[j].v := x;
    if (v[i].v > max)and(t >= k ) then
    begin
      max := v[i].v;
      maxi := v[j].i;
    end;
  end;

  writeln(maxi-k+1,' ',maxi,' ',max);


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