Pagini recente » Cod sursa (job #266134) | Cod sursa (job #1869245) | Cod sursa (job #1443952) | Cod sursa (job #718538) | Cod sursa (job #771861)
Cod sursa(job #771861)
var a,b:array[1..500000]of integer; i,n,k,p,u,m:integer;
buf: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);
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);
p:=m;
while (a[p-1]>=a[m]) and (i>1) do p:=p-1;
write(p,' ',i,' ',a[m]);
close(output);
end.