Cod sursa(job #772602)

Utilizator t.g.g.tt.g.g.t t.g.g.t Data 30 iulie 2012 12:23:46
Problema Secventa Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.96 kb
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; f:text;
begin
assign(f,'secventa.in'); reset(f); settextbuf(f,buf);
readln(f,n,k);a[n+1]:=-31000;
readln(f,s); close(f);
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(f,'secventa.out'); rewrite(f);
writeln(f,i,' ',p,' ',a[m]);
close(f);
end.