Pagini recente » Cod sursa (job #252465) | Cod sursa (job #1732305) | Cod sursa (job #2408460) | Cod sursa (job #2359190) | Cod sursa (job #457315)
Cod sursa(job #457315)
var v:array[1..500010]of integer;
d:array[1..50001]of longint;
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 (i>=k)and(max<v[d[p]]) then begin
max:=v[d[p]];
poz:=i;
end;
if d[p]<=i-k+1 then inc(p);
end;
assign(output,'secventa.out'); rewrite(output);
write(poz-k+1,' ',poz,' ',max);
close(output);
end.