Pagini recente » Cod sursa (job #1912437) | Cod sursa (job #338450) | Cod sursa (job #2251314) | Cod sursa (job #2308289) | Cod sursa (job #1199199)
var n,m,i,j,max,p:longint;
a,b,r,v:array[0..1050]of byte;
aib:array[0..1050]of longint;
function zeros(x:longint):longint;
begin
zeros := (x and (x-1))xor x;
end;
function maxim(pos:longint):longint;
begin
maxim := aib[pos];
repeat
if maxim < aib[pos] then maxim := aib[pos];
pos := pos - zeros(pos);
until pos = 0;
end;
procedure add(pos,v:longint);inline;
begin
repeat
if aib[pos] < v then
begin
aib[pos] := v;
pos := pos + zeros(pos);
end
else
break;
until pos > n;
end;
begin
assign(input,'cmlsc.in'); reset(input);
assign(output,'cmlsc.out'); rewrite(output);
readln(n,m);
for i := 1 to n do read(a[i]); readln();
for i := 1 to m do read(b[i]);
for i := 0 to n do aib[i] := 0;
for i := 1 to m do
begin
max := 0;
for j := 1 to n do
if a[j] = b[i] then
begin
max := maxim(j-1)+1;
add(j,max);
end;
r[i] := max;
end;
max := 0;
for i := 1 to n do
if r[i] > max then max := r[i];
writeln(max); p := max;
for i := n downto 1 do
if r[i] = max then
begin
v[max] := b[i];
dec(max);
end;
for i := 1 to p do write(v[i],' ');
close(input);
close(output);
end.