Cod sursa(job #457311)

Utilizator 05_YohnE1 La5c01 05_Yohn Data 18 mai 2010 21:18:09
Problema Secventa Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.5 kb
var v,d:array[1..500010]of integer;
n,k,i,p,u,max,poz:longint;
begin
assign(input,'secventa.in');reset(input);
read(n,k);
for i:=1 to n do read(v[i]);
p:=1;
u:=0;
max:=-30002;
for i:=1 to n do begin
    while (p<=u)and(v[i]<=v[d[u]]) do dec(u);
    inc(u);
    d[u]:=i;
    if d[p]<=i-k then inc(p);
    if (i>=k)and(max<v[d[p]]) then begin
       max:=v[d[p]];
       poz:=i;
    end;

end;
assign(output,'secventa.out'); rewrite(output);
write(poz-k+1,' ',poz,' ',max);
close(output);
end.