Cod sursa(job #495518)

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

function cautb(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 v[mij]=x then
         begin
         dr:=mij;
         break;
         end
            else
      if (v[mij]<x) and (x<v[mij+1]) then
         begin
         dr:=mij+1;
         break;
         end
          else
      if x<v[mij] then dr:=mij else
      if x>v[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);
read(f,x);
q:=1;
v[q]:=x;
b[1]:=1;
for i:=2 to n do
    begin
    read(f,x);
    if x>v[q] then
       begin
       q:=q+1;
       b[i]:=q;
       v[q]:=x;
       end
          else
       begin
       j:=cautb(q,x);
       v[j]:=x;
       b[i]:=j;
       end;
    end;
writeln(g,q);
close(f);
close(g);
end.