Pagini recente » Cod sursa (job #2368957) | Cod sursa (job #2539628) | Cod sursa (job #2380279) | Cod sursa (job #2562215) | Cod sursa (job #772588)
Cod sursa(job #772588)
var a:array[1..500001]of integer; b:array[1..500001]of longint;
p2,i,n,k,p,u,m,l:longint;
buf:array[1..1 shl 18]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); close(input);
i:=1;p2:=1; p:=1; u:=0; m:=n+1; l:=length(s);
while i<=l do
begin
if s[i]='-' then begin se:=true; inc(i); end else se:=false;
while ((i)<=l) and (s[i]<>' ') do
begin
a[p2]:=a[p2]*10+(ord(s[i])-48);
inc(i);
end;
if (i<=l) and (s[i]=' ') then inc(i);
if se then a[p2]:=-a[p2];
while (p<=u) and (a[p2]<a[b[u]]) do dec(u);
inc(u);
b[u]:=p2;
if (b[p]=p2-k) then inc(p);
if p2>=k then if a[m]<a[b[p]] then m:=b[p];
inc(p2);
end;
i:=m;
if i>1 then while (i>1) and (a[i-1]>=a[m]) do dec(i);
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.