On second thought, I did get it right. If it were a constant force, you'd have a rectangle under the graph of force vs. distance, and the area of that rectangle would be the total work. Since you have a sloping line that is zero at one side, you get a triangle, so the area is 1/2 base x height. Height at the point of maximum compression is kx, and base is x, so the area is (kx)(x)/2.