Applying work - energy theorem
Wtotal=ΔKblocks,cm+ΔKcm
As no external forces acting, the velocity of centre of mass will be constant. Hence ΔKcm=0.
Hence, Wtotal=ΔKblocks,cm
Wgravity=[12μv2rel]final−[12μv2rel]
−m1gh=0−12(m1m2m1+m2)(v1+v2)2
−m1gh=−12(m1m2m1+m2)(v1+v2)2
h=12m2(v1+v2)2g(m1+m2)
Thus, x=2