Cod sursa(job #759909)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 19 iunie 2012 20:00:17
Problema Subsir crescator maximal Scor 50
Compilator fpc Status done
Runda Arhiva educationala Marime 0.96 kb
Program Subsir_crescator_maximal; {Complexitate n*log_n}
 var a,b,c:array [0..100001] of longint;
     i,n,poz,l,max:longint;
     fi,fo:text;
procedure cauta(x:longint);
 var st,dr,mid:longint;
begin
 st:=1; dr:=l; mid:=(st+dr) div 2;
  while st<=dr do begin
                   mid:=(st+dr) div 2;
                   if c[mid]>x then st:=mid+1
                           else dr:=mid-1;
                   end;
 poz:=dr;
end;
begin
 assign(fi,'scmax.in');
  assign(fo,'scmax.out');
 reset(fi); rewrite(fo); readln(fi,n);
  for i:=1 to n do read(fi,a[i]);
   b[n]:=1; c[0]:=1000000; c[1]:=a[n]; l:=1; max:=1;
  for i:=n-1 downto 1 do begin
                          cauta(a[i]);
                           b[i]:=poz+1;
                            if poz=l then inc(l);
                            if c[poz+1]<a[i] then c[poz+1]:=a[i];
                           if b[i]>max then max:=b[i];
                           end;
  write(fo,max);
 close(fo);
end.