It's helpful here to draw a right-angle triangle, ABD.
A is the offshore well, D is the oil refinery.
AB = 2 km
BD = 4 km
C is somewhere between B and D such that BC = x and CD = 4-x
AC = path under the ocean = √(x²+2²)
CD= path on land = 4-x
Let y = cost per km on land
Cost of AC = 2y*√(x²+4)
Cost of CD = y(4-x)
Total Cost (C) = 2y√(x²+4) + y(4-x)
Hopefully you can take it from there.