Pagini recente » Cod sursa (job #959694) | Cod sursa (job #859266) | Cod sursa (job #1134475) | Cod sursa (job #1936213) | Cod sursa (job #65320)
Cod sursa(job #65320)
var a,b:array[1..500000]of integer;
n,k,i,j,st,fi,max,p,u:longint;
begin
assign(input,'secventa.in');
reset(input);
assign(output,'secventa.out');
rewrite(output);
readln(n,k);
st:=1;
fi:=1;
b[1]:=-31000;
for i:=1 to n do read(a[i]);
for i:=1 to k do
begin
fi:=fi+1;
b[fi]:=a[i];
for j:=fi-1 downto st do
begin
if b[j]>a[i] then dec(fi)
else
begin
b[j+1]:=a[i];
break;
end;
end;
end;
st:=st+1;
max:=-31000;
if b[st]>max then
begin
max:=b[st];
p:=1;
u:=k;
end;
for i:=k+1 to n do
begin
if b[st]=a[i-k] then st:=st+1;
fi:=fi+1;
b[fi]:=a[i];
for j:=fi-1 downto st do
begin
if b[j]>b[fi] then dec(fi)
else
begin
b[j+1]:=a[i];
break;
end;
end;
if b[st]>max then
begin
p:=i-k+1;
u:=i;
max:=b[st];
end;
end;
writeln(p,' ',u,' ',max);
close(output);
end.