Work done is equal to change in energy of body.
Situation is done in the figure. When mass `m` falls vertically on spring then spring is compresed by distance `d`.
Hence net work done in the process is
`W = ` Potential energy stored in the spring
`+` Loss of potential energy
` = mg (h + d) - (1)/(2) kd^(2)`