Pagini recente » Cod sursa (job #1143784) | Cod sursa (job #2723964) | Cod sursa (job #1552391) | Cod sursa (job #1997776) | Cod sursa (job #291389)
Cod sursa(job #291389)
var a,b,c:array[0..100000] of longint; f,g:text; i,m,x,n,nr:longint;
function caut(x:longint):longint;
var rasp,st,dr,mij:longint;
begin
rasp:=m; st:=0; dr:=m;
while st<=dr do
begin
mij:=(st+dr) shr 1;
if (c[mij]<x) and (c[mij+1]>=x) then
begin
rasp:=mij;
break;
end else
if c[mij+1]<x then st:=mij+1
else dr:=mij-1;
end;
caut:=rasp;
end;
begin
assign(f,'scmax.in'); reset(f);
assign(g,'scmax.out'); rewrite(g);
read(f,n); m:=1;
for i:=1 to n do
read(f,a[i]);
c[1]:=a[1]; b[1]:=1;
for i:=2 to n do
begin
x:=caut(a[i]);
b[i]:=x+1;
c[x+1]:=a[i];
if m<x+1 then
m:=x+1;
end;
writeln(g,m);
nr:=0; c[0]:=maxlongint;
for i:=n downto 1 do
if (b[i]=m) and (a[i]<c[nr]) then
begin
inc(nr);
c[nr]:=a[i];
dec(m);
end;
for i:=nr downto 1 do write(g,c[i],' ');
close(f); close(g);
end.