#P1664. 2024.1.30-后端开发机试-第一题

2024.1.30-后端开发机试-第一题

An AWS client has brought servers and databases from data centers in different parts ofthe world for their application. For simplicity, let's assume all the servers and data centersare located on a 1-dimensional line.

You have been given the task of optimizing the network connection. Each data centermust be connected to a server. The positions of n data centers and n servers are given inthe form of arrays. Any particular data center, center[i], can deliver to any particularserver destination, destination/j, The lag is defined distance between a data center atlocation xand a server destination at location y is |x-y|, i.e., the absolute differencebetween xand y. Determine the minimum lag to establish the entire network.

Example