CF1637D.Yet Another Minimization Problem
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays a and b , both of length n .
You can perform the following operation any number of times (possibly zero): select an index i ( 1≤i≤n ) and swap ai and bi .
Let's define the cost of the array a as ∑i=1n∑j=i+1n(ai+aj)2 . Similarly, the cost of the array b is ∑i=1n∑j=i+1n(bi+bj)2 .
Your task is to minimize the total cost of two arrays.
输入格式
Each test case consists of several test cases. The first line contains a single integer t ( 1≤t≤40 ) — the number of test cases. The following is a description of the input data sets.
The first line of each test case contains an integer n ( 1≤n≤100 ) — the length of both arrays.
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤100 ) — elements of the first array.
The third line of each test case contains n integers b1,b2,…,bn ( 1≤bi≤100 ) — elements of the second array.
It is guaranteed that the sum of n over all test cases does not exceed 100 .
输出格式
For each test case, print the minimum possible total cost.
输入输出样例
输入#1
3 1 3 6 4 3 6 6 6 2 7 4 1 4 6 7 2 4 2 5 3 5
输出#1
0 987 914
说明/提示
In the second test case, in one of the optimal answers after all operations a=[2,6,4,6] , b=[3,7,6,1] .
The cost of the array a equals to (2+6)2+(2+4)2+(2+6)2+(6+4)2+(6+6)2+(4+6)2=508 .
The cost of the array b equals to (3+7)2+(3+6)2+(3+1)2+(7+6)2+(7+1)2+(6+1)2=479 .
The total cost of two arrays equals to 508+479=987 .