Cod sursa(job #772596)

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