Spring work from to : W = k( - ). The work by the external agent is the negative of this.
Critical trap: Work from 0 to x is \frac{1}{2}$$kx^2. Work from x to 2x is \frac{3}{2}$$kx^2 (NOT another \frac{1}{2}$$kx^2). The spring force increases with deformation, so more work is needed for the same additional stretch.
Maximum compression when all KE converts to PE: \frac{1}{2}$$mv^2 = \frac{1}{2}$$kx_{max}^2, giving = v*sqrt.
For a body falling height h onto a spring: mg(h+x) = \frac{1}{2}$$kx^2 (must include the extra distance x the body falls during compression).