Cod sursa(job #574976)

Utilizator ion_calimanUAIC Ion Caliman ion_caliman Data 7 aprilie 2011 19:06:09
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.93 kb
var     best,a,poz:array[1..100000] of longint;
        max,sol,p,n,i,j:longint;
        s:string;
        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]);}
  i:=1;
  while not eoln(f1) do
    begin
      read(f1,s);
      for j:=1 to length(s) do
        if s[j]=' ' then inc(i) else a[i]:=a[i]*10+ord(s[j])-ord('0');
    end;

  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.