Pagini recente » Monitorul de evaluare | Cod sursa (job #1731) | Cod sursa (job #271792) | Cod sursa (job #2011869) | Cod sursa (job #1357064)
program scmax;
var
t,b,tt:array[1..100001]of longint;
i,j,nr,x,n:longint;
f,g:text;
function max(a,b:longint):longint;
begin
if a>b then
max:=a
else
max:=b;
end;
function cauta(xx,st,dr:longint):longint;
var m:longint;
begin
while st<=dr do
begin
m:=(st+dr) div 2;
if xx<=b[m] then
dr:=m-1
else
st:=m+1;
end;
cauta:=st;
end;
begin
assign (f,'scmax.in');
assign (g,'scmax.out');
reset (f
);
rewrite (g);
readln (f,n);
for i:=1 to n do
read (f,t[i]);
b[1]:=t[1]; x:=1; tt[1]:=1;
for i:=2 to n do
begin
j:=cauta(t[i],1,x);
b[j]:=t[i]; tt[i]:=j;
x:=max(x,j);
end;
nr:=x;
{ for i:=n downto 1 do
if tt[i]=nr then
begin
b[nr]:=t[i]; nr:=nr-1;
end; }
writeln (g,x);
for i:=1 to x do
write (g,b[i],' ');
close (f);
close (g);
end.