Question:
Given the N numbers of the two groups, you can adjust the order of numbers in the same group at will, and find the minimum value of sum Xi * Yi I = 1 .. n.
Small: n <= 8
Abs xy, Yi <= 1000
Large: n <= 800
Abs xi and Yi <= 100000
If the sum of the two numbers is fixed, the product of the two numbers is the largest and only the two numbers are as close as possible.
Therefore, intuition tells us that X is sorted in ascending order, and Y is sorted in descending order, and the obtained product is the largest.
Because the order can be adjusted at will, we can fix the order of numbers in X, just thinking about the order of numbers in Y.
Verification:
When N = 2:
If there are only two numbers, x1, x2, Y1, and Y2, it is assumed that the numbers with large numbers are also large.
X1 * y2 + x2 * Y1-(x1 * Y1 + x2 * Y2)
X1 (Y2-Y1) + X2 (y1-y2)
(X1-x2) (y2-y1) <0
Obviously, n = 2 is correct.
When N> 2:
Assume that in the optimal solution, there are ya, Yb, B> A and ya> Yb (not arranged in descending order). Obviously, according to n = 2, their positions are exchanged, you will get a smaller answer.
Therefore, the assumption is correct.
In addition, it is very important to note that in larger data, Xi * Yi may overflow int (10 ^ 10) and data needs to be properly selected.
Gcj -- Minimum scalar product (2008 round1 aa)