a. As the block is moving down, the spring pushes it up with a force `F_(sp)=kx`. The work done by the spring is
`W_(sp)=-1/2kx^2`
The work done by gravity is `W_gr=mgx`
The block does not change its kinetic energy as it is lowered slowly, `DeltaK=0`
Assuming `W_(ext)` as the work done by the applied external force by applying work-energy theorem, we have
Work done by total forces is equal to change in kinetic energy of the system.
`W_(total)=DeltaK`
`W_(ext)=W_(sp)+W_(gr)=DeltaK`
Substituting `W_(sp)=-1/2kx^2`, `W_(gr)=mgx`, and `DeltaK=0`, we
have `W_(ext)-1/2kx^2+mgx=0`
b. When the block remains at rest under the action of gravity and spring force, as the continuously increasing spring force `kx` will nullify the gravity force `mg`, we have `kx=mg`.
This gives `x=mg//k` which corresponds to stable euilibrium position. Now substituting `x=mg//k` in the expression,
`W_(ext)=1/2kx^2-mgx`, we have `W_(ext)=-(m^2g^2)/(2k)`