Absolute Beauty
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题面翻译
两个长度均为 的数组 。一次操作可以选择两个下标 ,交换 。你需要进行最多一次操作,最大化 。
题目描述
Kirill has two integer arrays and of length . He defines the absolute beauty of the array as
Here, denotes the absolute value of .
Kirill can perform the following operation at most once:
- select two indices and () and swap the values of and .
Help him find the maximum possible absolute beauty of the array after performing at most one swap.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases ( ). The description of test cases follows.
The first line of each test case contains a single integer ( ) — the length of the arrays and .
The second line of each test case contains integers ( ) — the array .
The third line of each test case contains integers ( ) — the array .
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output one integer — the maximum possible absolute beauty of the array after no more than one swap.
样例 #1
样例输入 #1
6
3
1 3 5
3 3 3
2
1 2
1 2
2
1 2
2 1
4
1 2 3 4
5 6 7 8
10
1 8 2 5 3 5 3 1 1 3
2 9 2 4 8 2 3 5 3 1
3
47326 6958 358653
3587 35863 59474
样例输出 #1
4
2
2
16
31
419045
提示
In the first test case, each of the possible swaps does not change the array .
In the second test case, the absolute beauty of the array without performing the swap is . After swapping the first and the second element in the array , the absolute beauty becomes . These are all the possible outcomes, hence the answer is .
In the third test case, it is optimal for Kirill to not perform the swap. Similarly to the previous test case, the answer is .
In the fourth test case, no matter what Kirill does, the absolute beauty of remains equal to .