Cod sursa(job #680640)

Utilizator andreiseiceanSeicean Andrei andreiseicean Data 15 februarie 2012 19:55:46
Problema Subsir crescator maximal Scor 65
Compilator fpc Status done
Runda Arhiva educationala Marime 0.83 kb
var f,g:text;
    n,i,max,j,poz:longint;
    a,lung:array[0..100000]of longint;
begin
assign(f,'scmax.in'); reset(f); assign(g,'scmax.out');rewrite(g);
read(f,n);
for i:=0 to n-1 do
   read(f,a[i]);
lung[n-1]:=1;
for i:=n-2 downto 0 do
   begin
      max:=0;
      for j:=i+1 to n-1 do
        if a[i]<a[j] then if max<lung[j] then max:=lung[j];
      lung[i]:=max+1;
    end;
max:=lung[0];
poz:=0;
for i:=1 to n-1 do
   if max<lung[i] then begin max:=lung[i]; poz:=i;end;
writeln(g,max);
write(g,a[poz],' ');max:=max-1;
for i:=poz+1 to n-1 do
   if (lung[i]=max)and(a[i]>poz) then begin
                                        write(g,a[i],' ');
                                        poz:=i;
                                        max:=max-1;
                                      end;
close(f);
close(g);
end.