Cod sursa(job #1138741)

Utilizator Vasile_Catananoname Vasile_Catana Data 10 martie 2014 15:40:33
Problema Subsir crescator maximal Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 1.09 kb
program scmax;
var a,v,best:array[0..100001] of longint;
    f,g:text;
    b1,b2:array[0..1 shl 17 ] of char;
    ni,poz,j,t,n,i:longint;
function cauta(x:longint):longint;
var i_n,s_f,mid:longint;
 begin
 i_N:=1;
 s_f:=v[0];
 while I_n<=s_F do
        begin
        mid:=(i_n+s_f) div 2;
         if x<=v[mid] then
                s_f:=mid-1
                else
                i_n:=mid+1;
        end;
 cauta:=i_N;
end;
begin
assign(f,'scmax.in');reset(F);settextbuf(f,b1);
assign(g,'scmax.out');rewrite(G);settextbuf(g,b2);
readln(F,n);
  for i:=1 to n do read(f,a[i]);
  v[1]:=a[1];
  v[0]:=1;
  best[1]:=1;
  for i:=2 to n do
        begin
        poz:=cauta(a[i]);
        v[poz]:=a[i];
        best[i]:=poz;
        if v[0]<poz then v[0]:=poz;
        end;
  writeln(g,v[0]);
  j:=v[0];
  t:=0;
  while i>=1 do begin
        if best[i]=j then
                begin
                dec(J);
                inc(T);
                v[t]:=a[i];
                end;
        dec(I);
        end;
  for i:=t downto 1 do write(g,v[i],' ');
close(F);
close(G);
end.