CF1898D.Absolute Beauty
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Kirill has two integer arrays a1,a2,…,an and b1,b2,…,bn of length n. He defines the absolute beauty of the array b as
i=1∑n∣ai−bi∣
Here, ∣x∣ denotes the absolute value of x.
Kirill can perform the following operation at most once:
- select two indices i and j (1≤i<j≤n) and swap the values of bi and bj.
Help him find the maximum possible absolute beauty of the array b after performing at most one swap.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤10000 ). The description of test cases follows.
The first line of each test case contains a single integer n ( 2≤n≤2⋅105 ) — the length of the arrays a and b .
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the array a .
The third line of each test case contains n integers b1,b2,…,bn ( 1≤bi≤109 ) — the array b .
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, output one integer — the maximum possible absolute beauty of the array b after no more than one swap.
输入输出样例
输入#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 b .
In the second test case, the absolute beauty of the array b without performing the swap is ∣1−1∣+∣2−2∣=0 . After swapping the first and the second element in the array b , the absolute beauty becomes ∣1−2∣+∣2−1∣=2 . These are all the possible outcomes, hence the answer is 2 .
In the third test case, it is optimal for Kirill to not perform the swap. Similarly to the previous test case, the answer is 2 .
In the fourth test case, no matter what Kirill does, the absolute beauty of b remains equal to 16 .