Minimum Scalar Product (Large)
InterviewTime limit5sMemory limit512 MB
Reorder the coordinates of two equal-length integer vectors so their scalar product is as small as possible, and report that minimum for each test case.
- Level
Medium4 of 10
- Topics
- Sorting, Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
You are given two integer vectors of the same length, and . The scalar product of the two vectors is the single number .
You may reorder the coordinates of each vector however you like. Permute the coordinates of both vectors so that the scalar product is as small as possible, and print that minimum.
Input
The first line contains the number of test cases .
Each test case takes three lines. The first line contains an integer . The next two lines contain integers each: the coordinates of on the second line and the coordinates of on the third line.
Limits
Output
For each test case, print one line in this format.
Case #X: Y
is the test case number starting from 1, and is the smallest scalar product obtainable by permuting the coordinates of the two vectors.