Pagini recente » Cod sursa (job #226211) | Cod sursa (job #1127937) | Cod sursa (job #2529836) | Cod sursa (job #1615796) | Cod sursa (job #222631)
Cod sursa(job #222631)
var f,g:text;
v,q,p:array[0..500010]of longint;
n,k,i,st,dr,max,p2,j,x:longint;
c:array[1..3500005]of char;
s:char;
begin
assign(f,'secventa.in');
assign(g,'secventa.out');
reset(f);
rewrite(g);
readln(f,n,k);
readln(f,c);
i:=1;
n:=0;
x:=0;
s:='+';
while (c[i] in (['0'..'9']+[' ']+['-']))do
begin
if (c[i]=' ')then
begin
if (s='-')then
begin
if (x>0)then x:=-x;
end else
if (x<0)then x:=-x;
inc(n);
v[n]:=x;
x:=0;
s:='+';
end else
if (c[i]='-')then s:='-' else
begin
if (i=1)or(c[i-1]='-')then
x:=x*10+ord(c[i])-ord('0')else
x:=x*10+ord(c[i])-ord('0');
end;
inc(i);
end;
inc(n);
v[n]:=x;
st:=1;
dr:=1;
q[1]:=v[1];
p[1]:=1;
max:=-30001;
if (1=k)then
max:=q[st];
p2:=1;
for i:=2 to n do
begin
while (v[i]<=q[dr])and(dr>=st)do
dec(dr);
inc(dr);
q[dr]:=v[i];
p[dr]:=i;
if (i>=k)then
begin
while (p[st]<i-k+1)do inc(st);
if (q[st]>max)then
begin
max:=q[st];
p2:=i;
end;
end;
end;
write(g,p2-k+1,' ',p2,' ',max);
close(f);
close(g);
end.