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
step1:题目简化
本质就是给定两个长度相等为n的数组a,b , 求一种排列顺序使得对应位置两两相减的绝对值的和最小。
step2:贪心
我们不妨先规定a是升序的,那么任务就是只需要给b一个顺序,使得两两绝对值的和最小。
本题属于以下题库,请选择所需题库进行购买