Cod sursa(job #268366)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 1 martie 2009 10:29:08
Problema Subsir crescator maximal Scor 60
Compilator fpc Status done
Runda Arhiva educationala Marime 0.97 kb
var  
   i,j,n,max,p:longint;   
   f:text;   
   poz,a,l:array[1..100000] of longint;   
Begin   
     assign(f,'scmax.in');   
     reset(f);   
     readln(f,n);   
     for i:=1 to n do  
         read(f,a[i]);   
     close(f);   
     L[n]:=1;
     poz[n]:=-1;
     for i:=n-1 downto 1 do
     begin
          L[i]:=1;
          poz[i]:=-1;
          for j:=i+1 to n do
            if (a[i]<=a[j]) and (L[i]<1+L[j]) then
                          begin
                               L[i]:=1+L[j];
                               poz[i]:=j;
                          end;
     end;
     max:=L[1];p:=1;
     for i:=2 to n do
         if max<L[i] then begin
                               max:=L[i];
                               p:=i;
                          end;
     assign(f,'scmax.out'); rewrite(f);
     writeln(f,max);
     i:=p;
     while i<>-1 do
     begin
          write(f,a[i],' ');
          i:=poz[i];
     end;
     close(f);
End.