Cod sursa(job #933373)
program subisl;
var f,g:text;
v:array[1..100000] of longint;
q:array[0..100000] of longint;
s:array[0..100000] of longint;
bufin,bufout:array[1..65000] of byte;
n,i,j,nr,lungime:longint;
solutie:array[1..100000] of longint;
begin
assign (f,'scmax.in'); reset (f);
assign (g,'scmax.out'); rewrite (g);
settextbuf (f,bufin);
settextbuf (g,bufout);
readln (F,n);
for i:=1 to n do
begin
read (f,v[i]);
end;
nr:=0;
for i:=1 to n do
begin
if v[i]>s[nr] then
begin
inc(nr);
s[nr]:=v[i];
q[i]:=nr;
end
else
begin
for j:=1 to nr do
if s[j]>=v[i] then
begin
s[j]:=v[i];
q[i]:=j;
break;
end;
end;
end;
writeln (g,nr);
lungime:=nr;
for i:=n downto 1 do
begin
if q[i]=nr then
begin
solutie[nr]:=v[i];
dec(nr);
end;
end;
for i:=1 to lungime do write (g,solutie[i],' ');
close (f); close (g);
end.