Cod sursa(job #744608)

Utilizator Hexman1994Negoita Radu Hexman1994 Data 9 mai 2012 11:00:05
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.69 kb
var a,l:array[1..100000] of longint;
    i,max,mx,j,n,p,u:longint;
begin
assign(input,'scmax.in');reset(input);
assign(output,'scmax.out');rewrite(output);
read(n);
for i:=1 to n do read(a[i]);
l[n]:=1;
mx:=0;
for i:=n-1 downto 1 do begin
    max:=0;
    for j:=i+1 to n do
        if (l[j]>max) and (a[i]<a[j]) then
           max:=l[j];
    l[i]:=max+1;
    if l[i]>mx then begin
       p:=i;
       mx:=l[i];
       end;
    end;
write(mx);
writeln;
write (a[p],' ');
u:=a[p];
dec(mx);
for i:=p+1 to n do
    if (a[i]>u) and (l[i]=mx) then begin
                write(a[i],' ');
                u:=a[i];
                dec(mx);
                end;
close(output);
end.