Cod sursa(job #65313)

Utilizator raduzerRadu Zernoveanu raduzer Data 8 iunie 2007 13:40:57
Problema Secventa Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.14 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 break;
          end;
          b[j+1]:=a[i];
          fi:=j+1;;
     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 break;
          end;
          b[j+1]:=a[i];
          fi:=j+1;
          if b[st]>max then
          begin
               p:=i-k+1;
               u:=i;
               max:=b[st];
          end;
     end;
     writeln(p,' ',u,' ',max);
close(output);
end.