The minimum height h,through which the system be released from rest and the spring is unstretched initially,is
xmgk .And collision between block B and surface is perfectly inelastic,such as after collision between B and ground 'B' may be lifted off from the ground after collision then x is:
(spring constant=k)