Pagini recente » Cod sursa (job #1686465) | Cod sursa (job #1940976) | Cod sursa (job #1684262) | Cod sursa (job #2779987) | Cod sursa (job #771873)
Cod sursa(job #771873)
var a,b:array[1..500001]of longint; i,n,k,p,u,m:longint;
buf:array[1..1 shl 19]of char;
begin
assign(input,'secventa.in'); reset(input); settextbuf(input,buf);
readln(n,k);a[n+1]:=-31000;
for i:=1 to n do read(a[i]);
p:=1; u:=0; m:=n+1;
assign(output,'secventa.out'); rewrite(output);
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;
if i>1 then while (i>1) and (a[i-1]>=a[m]) do i:=i-1;
p:=m-i+1; if p<k then p:=i+k-1 else p:=m;
writeln(i,' ',p,' ',a[m]);
close(output);
end.