Here is a video I made to illustrate what is happening in this problem (notice how the amount of cable is dependent on where the point (x,0) is):
https://drive.google.com/file/d/1Y0j770fXqr_Fg6DHbJCUp4YdjJVxb7xf/view?usp=sharing
The critical piece here is the formula for the total distance (named D in the video). It is found by summing the distances of each town from the point (x,0) using the distance formula. Definitely do this on your own and verify my algebra. Then you just take the derivative and set to zero, solve for x, verify that it is in fact a minimum with second derivative.
Visualization can be a big help in these types of problems. Always try to draw a diagram.