Given ensuing information, determine the least cost and the least cost mix of on-

and off-shore pipe.

The intake facility is in the water 2 miles vertically north of the shoreline
The water filtration plant is on land 1 mile vertically south of the shoreline
The intake and the plant are horizontally 3 miles apart
The cost to lay pipe off-shore is $60,000 per mile and the cost to lay pipe on-
shore is $30,000 per mile
The shoreline runs east and west in a horizontal straight line

Answer:
If the pipe comes ashore x miles from the point directly south of the intake, the cost (in $K) is

c(x) = 60√(x^2+4) + 30√((3-x)^2 + 1)
dc/dx = 60x/√(x^2+4) - 30(3-x)/√((3-x)^2 + 1)

dc/dx=0 when x=1

So, we have √5 miles of offshore pipe and √5 miles of onshore pipe.
Cost = 90√5 $K = $201,246.12

HOWEVER, I do not get how to get √(x^2+4) and √((3-x)^2 + 1)

Please explain!