Cod sursa(job #1199250)

Utilizator vasica38Vasile Catana vasica38 Data 18 iunie 2014 17:58:19
Problema Subsir crescator maximal Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.71 kb
type tabel=array[1..1000000]of longint;
var t,max,poz:tabel;
    i,j,k,m,n:longint;
begin
 assign(input,'scmax.in');
 reset(input);
 readln(n) ;
 for i:=1 to n do read(t[i]) ;
 close(input);

 max[1]:=1;
 m:=1;
 for i:=2 to n do
  begin
    for j:=1 to i-1 do
     begin
      if (t[j]<t[i])and(max[j]=m) then
                                     begin
                                      if max[j]+1>max[i]then max[i]:=max[j]+1;
                                      m:=m+1;
                                     end
     end;
  end;

 assign(output,'scmax.out');
 rewrite(output);
 writeln(m);
 if m=1 then write(t[1])else
 for i:=1 to n do if max[i]<>0 then write(t[i],' ');
 close(output);
end.