Cod sursa(job #562417)

Utilizator ion_calimanUAIC Ion Caliman ion_caliman Data 22 martie 2011 22:51:56
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.73 kb
var     best,a,poz:array[1..100000] of longint;
        max,sol,p,n,i,j:longint;
        f1,f2:text;

begin
  assign(f1,'scmax.in');
  assign(f2,'scmax.out');
  reset(f1);
  rewrite(f2);
  readln(f1,n);
  for i:=1 to n do
   read(f1,a[i]);

  best[n]:=1;
  poz[n]:=-1;
  max:=1;
  p:=n;
  for i:=n-1 downto 1 do
    begin
      best[i]:=1;
      poz[i]:=-1;
      for j:=i+1 to n do
        if (a[i]<a[j])and(best[i]<best[j]+1) then
          begin
            best[i]:=best[j]+1;
            poz[i]:=j;
            if best[i]>max then begin max:=best[i]; p:=i; end;
          end;
    end;
  writeln(f2,max);
  i:=p;
  while i>0 do
    begin
      write(f2,a[i],' ');
      i:=poz[i];
    end;
  close(f2);
end.