Pagini recente » Cod sursa (job #2886795) | Cod sursa (job #2154849) | Cod sursa (job #1366798) | Cod sursa (job #238925) | Cod sursa (job #772630)
Cod sursa(job #772630)
CONST
tfi ='secventa.in';
tfo ='secventa.out';
nmax =500000;
TYPE
arr =array [1..nmax] of longint;
VAR
fi,fo :text;
n,k,top,max,d,c:longint;
a,b,st :arr;
(********************************************************************)
Procedure nhap;
Var
i :longint;
Begin
assign(fi,tfi);reset(fi);
read(fi,n,k);
for i:=1 to n do read(fi,a[i]);
close(fi);
End;
(*********************************************************************)
Procedure push(x:longint);
Begin
inc(top);
st[top]:=x;
End;
(**********************************************************************)
Procedure lam;
Var
i,t,dem :longint;
Begin
push(1);
t:=1;
dem:=0;
for i:=1 to n do
begin
if i-st[t]>=k then inc(t);
while (top>=t) and (a[i]<=a[st[top]]) do dec(top);
push(i);
if i>=k then
begin
inc(dem);
b[dem]:=st[t];
end;
end;
for i:=1 to dem do if a[b[i]]>max then
begin
max:=a[b[i]];
d:=i;
c:=i+k-1;
end;
End;
(************************************************************************)
Procedure inkq;
Begin
assign(fo,tfo);rewrite(fo);
write(fo,d,' ',c,' ',max);
close(fo);
End;
(************************************************************************)
BEGIN
nhap;
lam;
inkq;
END.