Introduction - If you have any usage issues, please Google them yourself
According to the subject analysis, it is assumed that the chief pipeline is located on the east side of all pipes (or the west side), the total length of the oil pipeline between the oil well and the main pipe is sum1. If the position of the main pipe is located in the middle of all the longitudinal coordinates of the pipe, the total length of the pipeline is sum2. Thus, sum1>=sum2 can be calculated. So I use second ideas to transform the problem into the problem of finding K number in N numbers.
The length of the total oil pipeline can be obtained by reducing the median value of each oil pipeline, and finally, it can solve the problem.
According to the requirements of the subject, we need to determine the optimal location of the main pipeline in a linear time. In the sorting algorithm, the best is the fast sorting, and according to the title, we do not need to sort all the N numbers, so we can use the idea of fast sorting to achieve the goal.