Cod sursa(job #238519)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 2 ianuarie 2009 14:12:22
Problema Secventa Scor 80
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.67 kb
program alex;
var f:text;
    i,n,k,j,ls,li,max,poz:longint;
    a,c:array[1..500010]of longint;
begin
assign(f,'secventa.in');reset(f);
readln(f,n,k);
for i:=1 to n do
   read(f,a[i]);
close(f);
li:=1;
ls:=0;
max:=-30001;
for i:=1 to n do
    begin
    while(li<=ls)and(a[i]<=a[c[ls]])do
          ls:=ls-1;
    ls:=ls+1;
    c[ls]:=i;
    if c[li]=i-k then li:=li+1;
    if i>=k then if a[c[li]]>max then begin
                                      max:=a[c[li]];
                                      poz:=i-k+1;
                                      end;
    end;
assign(f,'secventa.out');rewrite(f);
write(f,poz,' ',poz+k-1,' ',max);
close(f);
end.