#P3236. [HNOI2014] 画框
[HNOI2014] 画框
Description
Xiao T (小 T) plans to place several paintings at home. He has bought paintings and frames. To show his taste, he wants to match paintings with frames so that the result is neither too plain nor too jarring.
For the pairing of painting with frame , Xiao T assigns a plainness value and an incompatibility value . The overall disharmony of a complete matching is defined as the product of the sum of plainness values over all matched pairs and the sum of incompatibility values over all matched pairs. Specifically, let painting be matched with frame ; then the overall disharmony is
$$\mathrm{disharmony}=\sum_{i=1}^{N}A_{i,p_i}\times \sum_{i=1}^{N}B_{i,p_i}.$$Xiao T wants to know the minimum possible overall disharmony.
Input Format
The first line contains a positive integer , the number of test cases. For each test case:
- The first line contains a positive integer , the number of paintings and frames.
- Lines through each contain non-negative integers; on line , the -th number is .
- Lines through each contain non-negative integers; on line , the -th number is .
Output Format
Output lines, each containing one integer: the minimum overall disharmony.
1
3
4 3 2
2 3 4
3 2 1
2 3 2
2 2 4
1 1 3
30
Hint
If painting is matched with frame , painting with frame , and painting with frame , then the overall disharmony is .
Constraints: For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号