Pagini recente » Cod sursa (job #561208) | Cod sursa (job #229305) | Cod sursa (job #132599) | Cod sursa (job #2183577) | Cod sursa (job #771859)
Cod sursa(job #771859)
var a,b:array[1..500000]of integer; i,n,k,p,u,m:integer;
buf,buf2:array[1..1 shl 18]of char;
begin
assign(input,'secventa.in'); reset(input); settextbuf(input,buf);
readln(n,k);
for i:=1 to n do read(a[i]);
p:=1; u:=0; m:=1;
assign(output,'secventa.out'); rewrite(output); settextbuf(output,buf2);
for i:=1 to n do
begin
while (p<=u) and (a[i]<a[b[u]]) do u:=u-1;
u:=u+1;
b[u]:=i;
if (b[p]=i-k) then p:=p+1;
if i>=k then if a[m]<a[b[p]] then m:=b[p];
end;
i:=m;
while (a[i+1]>=a[m]) and (i<n) do inc(i);
while a[i]>=a[m] do begin write(a[i],' '); i:=i-1; end;
close(output);
end.