A useful statement of mechanical energy conservation is
K_{rm i} + U_{rm i} = E_{rm i} = E_{rm f} = K_{rm f} + U_{rm f}.
Initially, the spring was compressed a distance x_0; its total initial energy was E_{rm i} = (1/2)kx_0^2 (neglecting the potential energy from the small change in height, x_0).
Find the total mechanical energy of the ball when it is a height h above the equilibrium position of the spring. Assume that h < h_{rm max} , so that the ball has some velocity v. Define the gravitational potential energy to be zero at the equilibrium height of the spring.
Express the total mechanical energy in terms of h, v, g, and the ball's mass m.