#P13457. [GCJ 2008 #1A] Minimum Scalar Product

[GCJ 2008 #1A] Minimum Scalar Product

题目描述

You are given two vectors v1=(x1,x2,...,xn)v_1 = (x_1, x_2, ..., x_n) and v2=(y1,y2,...,yn)v_2 = (y_1, y_2, ..., y_n). The scalar product of these vectors is a single number, calculated as x1y1+x2y2+...+xnynx_1y_1 + x_2y_2 + ... + x_ny_n.

Suppose you are allowed to permute the coordinates of each vector as you wish. Choose two permutations such that the scalar product of your two new vectors is the smallest possible, and output that minimum scalar product.

输入格式

The first line of the input file contains integer number TT - the number of test cases. For each test case, the first line contains integer number nn. The next two lines contain nn integers each, giving the coordinates of v1v_1 and v2v_2 respectively.

输出格式

For each test case, output a line

Case #XX: YY

where XX is the test case number, starting from 1, and YY is the minimum scalar product of all permutations of the two given vectors.

2
3
1 3 -5
-2 4 1
5
1 2 3 4 5
1 0 1 0 1
Case #1: -25
Case #2: 6

提示

Limits

Small dataset (5 Pts, Test set 1 - Visible)

  • T=1000T = 1000
  • 1n81 \leq n \leq 8
  • 1000xi,yi1000-1000 \leq x_i, y_i \leq 1000

Large dataset (10 Pts, Test set 2 - Hidden)

  • T=10T = 10
  • 100n800100 \leq n \leq 800
  • 100000xi,yi100000-100000 \leq x_i, y_i \leq 100000