Cod sursa(job #1096070)

Utilizator DjokValeriu Motroi Djok Data 1 februarie 2014 15:01:08
Problema Subsir crescator maximal Scor 60
Compilator fpc Status done
Runda Arhiva educationala Marime 0.88 kb
var a,a1: array[1..100000] of longint;
    t,i,k1,max,max1,n: longint;

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

 a1[n]:=1;
 for k1:=n-1 downto 1 do Begin
                         max:=0;
                         for i:=(k1+1) to n do
                         if (a[i]>=a[k1]) and (a1[i]>max) then max:=a1[i];
                         a1[k1]:=max+1;
                         if a1[k1]>max1 then begin max1:=a1[k1]; t:=k1; end;
                        end;
 writeln(max1);
 write(a[t],' ');
 for i:=t+1 to n do
  if ((a[i]>=a[t]) and (a1[i]=max1-1)) then begin
                                                 write(a[i],' ');
                                                 max1:=max1-1;
                                            end;


close(input);
close(output);
end.