Pagini recente » Cod sursa (job #123712) | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #1704472) | Cod sursa (job #772002)
Cod sursa(job #772002)
var a:array[1..500001]of integer; b:array[1..500001]of longint; p2,i,n,k,p,u,m:longint;
buf:array[1..1 shl 19]of char; s:ansistring; se:boolean;
begin
assign(input,'secventa.in'); reset(input); settextbuf(input,buf);
readln(n,k);a[n+1]:=-31000;
readln(s);i:=1;p2:=1; p:=1; u:=0; m:=n+1;
while i<=length(s) do
begin
if s[i]='-' then begin se:=true; i:=i+1; end else se:=false;
while ((i)<=length(s)) and (s[i]<>' ') do
begin
a[p2]:=a[p2]*10+(ord(s[i])-48);
i:=i+1;
end;
if (i<=length(s)) and (s[i]=' ') then inc(i);
if se then a[p2]:=-a[p2];
while (p<=u) and (a[p2]<a[b[u]]) do u:=u-1;
u:=u+1;
b[u]:=p2;
if (b[p]=p2-k) then p:=p+1;
if p2>=k then if a[m]<a[b[p]] then m:=b[p];
p2:=p2+1;
end;
i:=m;
if i>1 then while (i>1) and (a[i-1]>=a[m]) do i:=i-1;
p:=m-i+1; if p<k then p:=i+k-1 else p:=m;
assign(output,'secventa.out'); rewrite(output);
writeln(i,' ',p,' ',a[m]);
close(output);
end.