Cod sursa(job #1111284)

Utilizator atatomirTatomir Alex atatomir Data 18 februarie 2014 19:26:24
Problema Secventa Scor 20
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 := -30005;

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

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


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