Cod sursa(job #1205472)

Utilizator Alex1199Alex Bercea Alex1199 Data 6 iulie 2014 19:32:35
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.78 kb
var a, d: array[1..100010] of int64;
    n, i, k, j, max : longint;
    buf1 : array[1..1 shl 17] of char;
begin
 Assign(input,'scmax.in');
 reset(input);
 settextbuf(input, buf1);
 readln(n);
 For i:=1 to n do
   Read(a[i]);
 Close(input);
   d[n]:=1;
 For i:=n-1 downto 1 do
 begin max:=0;
   For j:=i+1 to n do
         if (a[i]<a[j]) and (max<d[j]) then
               max:=d[j];
    D[i]:=max+1;
 end;



 Assign(output,'scmax.out');
 rewrite(output);

  max:=0;
 for i:=1 to n do
   if d[i]>max then
   begin
       max:=d[i];
       k:=i;
   end;

   writeln(d[k]);
     j:=d[k];
     write(a[k],' ');
 For i:=k+1 to n do
     begin
    if d[i]+1=j then
     begin
      write(a[i],' ');
      j:=d[i];
     end;


    end;
 Close(output);
end.