Pagini recente » Cod sursa (job #3253200) | Cod sursa (job #2529506) | Cod sursa (job #2783021) | Cod sursa (job #673720) | Cod sursa (job #1091971)
var a,b:array[1..100000] of longint;
i,j,k,n,max:longint;
f,g:text;
begin
assign(f,'scmax.in');reset(f);
assign(g,'scmax.out');rewrite(g);
readln(f,n);
for i:=1 to n do
read(f,a[i]);
for i:=1 to n do
b[i]:=1;
for i:=n downto 1 do
for j:=i+1 to n do
if (a[j]>a[i]) and (b[j]+1 >b[i]) then b[i]:=b[j]+1;
for i:=1 to n do
if b[i]>max then max:=b[i];
writeln(g,max);
for i:=1 to n do
begin
if b[i]=max then
begin
write(g,a[i],' ');
dec(max);
end;
end;
close(f);close(g);
end.