Pagini recente » Cod sursa (job #673595) | Cod sursa (job #1750944) | Cod sursa (job #84900) | Cod sursa (job #425499) | Cod sursa (job #65321)
Cod sursa(job #65321)
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
begin
b[j]:=a[i];
dec(fi);
end
else break;
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
begin
b[j]:=b[fi];
dec(fi);
end
else break;
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.