Pagini recente » Cod sursa (job #2970651) | Cod sursa (job #1943737) | Cod sursa (job #1455000) | Cod sursa (job #2509243) | Cod sursa (job #457309)
Cod sursa(job #457309)
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[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.