Cod sursa(job #495516)

Utilizator andreii1Ilie Andrei andreii1 Data 25 octombrie 2010 18:42:44
Problema Subsir crescator maximal Scor 5
Compilator fpc Status done
Runda Arhiva educationala Marime 1.02 kb
type vector=array[1..100000] of longint;
var x,q,i,n:longint;
    a,v,b:vector;
    f,g:text;

function cautb(a:vector;n,x:longint):longint;
var st,dr,mij:longint;
    ok:boolean;
begin

st:=1;
dr:=n;
ok:=false;
while (ok=false) and (st<=dr) do
      begin
      mij:=(st+dr) div 2;
      if st=dr then ok:=true else
      if a[mij]=x then
         begin
         dr:=mij;
         break;
         end
            else
      if (a[mij]<x) and (x<a[mij+1]) then ok:=true else
      if x<a[mij] then dr:=mij else
      if x>a[mij] then st:=mij+1 else
      end;
cautb:=dr;
end;

begin
assign(f,'scmax.in'); reset(f);
assign(g,'scmax.out'); rewrite(g);
read(f,n);
for i:=1 to n do read(f,a[i]);
q:=1;
v[q]:=a[1];
b[1]:=1;
for i:=2 to n do
    begin
    if a[i]>v[q] then
       begin
       q:=q+1;
       b[i]:=q;
       v[q]:=a[i];
       end
          else
       begin
       x:=cautb(v,q,a[i]);
       v[x]:=a[i];
       b[i]:=x;
       end;
    end;
writeln(g,q);
close(f);
close(g);
end.