Cod sursa(job #65321)

Utilizator raduzerRadu Zernoveanu raduzer Data 8 iunie 2007 13:50:52
Problema Secventa Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.29 kb
var a,b:array[1..500000]of integer;
    n,k,i,j,st,fi,max,p,u:longint;
begin
     assign(input,'secventa.in');
     reset(input);
     assign(output,'secventa.out');
     rewrite(output);
     readln(n,k);
     st:=1;
     fi:=1;
     b[1]:=-31000;
     for i:=1 to n do read(a[i]);
     for i:=1 to k do
     begin
          fi:=fi+1;
          b[fi]:=a[i];
          for j:=fi-1 downto st do
          begin
               if b[j]>a[i] then
               begin
                    b[j]:=a[i];
                    dec(fi);
               end
               else break;
          end;
     end;
     st:=st+1;
     max:=-31000;
     if b[st]>max then
     begin
          max:=b[st];
          p:=1;
          u:=k;
     end;
     for i:=k+1 to n do
     begin
          if b[st]=a[i-k] then st:=st+1;
          fi:=fi+1;
          b[fi]:=a[i];
          for j:=fi-1 downto st do
          begin
               if b[j]>b[fi] then
               begin
                    b[j]:=b[fi];
                    dec(fi);
               end
               else break;
          end;
          if b[st]>max then
          begin
               p:=i-k+1;
               u:=i;
               max:=b[st];
          end;
     end;
     writeln(p,' ',u,' ',max);
close(output);
end.