Pagini recente » Cod sursa (job #725021) | Cod sursa (job #15200) | Cod sursa (job #858985) | Cod sursa (job #1428488) | Cod sursa (job #1362328)
program asa;
var f,g:text;
n,i,k,pozitie,aux:longint;
v,b,lung:array of longint;
function cauta(X,st,dr:longint):longint;
var mij:longint;
begin
while st <= dr do
begin
mij:=(st + dr) div 2;
if x <= b[mij] then
dr:=mij-1
else
st:=mij+1;
end;
cauta:=st;
end;
begin
assign(f,'scmax.in'); reset(f);
assign(g,'scmax.out'); rewrite(g);
readln(f,n);
setlength(v,n+1); //numerele
setlength(b,n+1); //cu asta jonglez
setlength(lung,n+1); //lungimile
for i:=1 to n do
begin
read(f,v[i]);
end;
b[1]:=v[1];
lung[1]:=1;
k:=1; //numarul de element din vectorul B
for i:=2 to n do
begin
pozitie:=cauta(v[i],1,k); //caut pozitia
b[pozitie]:=v[i]; //il adaug in B
lung[i]:=pozitie;
if pozitie > k then //actualizez lungimea lui B
k:=pozitie;
end;
writeln(g,k); aux:=k;
//parcurg descrescator
for i:=n downto 1 do
begin
if lung[i] = k then
begin
b[k]:=v[i];
dec(k);
end;
end;
for i:=1 to aux do
write(g,b[i],' ');
close(f); close(g);
end.