Pagini recente » Cod sursa (job #3171185) | Cod sursa (job #2776546) | Cod sursa (job #1699721) | Cod sursa (job #3285139) | Cod sursa (job #1419675)
const
tfi='secventa.in';
tfo='secventa.out';
oo=2000000000;
var
n,fir,last,res,fro,ba,k:longint;
a,queue:array[1..500000] of longint;
procedure inp;
var
i:longint;
begin
read(n,k);
for i:= 1 to n do read(a[i]);
end;
procedure process;
var
i:longint;
begin
res:=-oo;
fro:=1;ba:=0;
for i:= 1 to k do
begin
while (fro<=ba) and (a[i]<queue[ba]) do dec(ba);
inc(ba);
queue[ba]:=a[i];
end;
if queue[fro]>res then
begin
res:=queue[fro];
fir:=1;
last:=k;
end;
for i:= k+ 1 to n do
begin
while (fro<=ba) and (a[i]<queue[ba]) do dec(ba);
inc(ba);
queue[ba]:=a[i];
if a[i-k]=queue[fro] then inc(fro);
if queue[fro]>res then
begin
res:=queue[fro];
fir:=i-k+1;
last:=i;
end;
end;
writeln(fir,' ',last,' ',res);
end;
begin
assign(input,tfi);reset(input);
assign(output,tfo);rewrite(output);
inp;
process;
close(input);close(output);
end.