forwhat00  
B. Gifts Fixing

You have nn gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The ii-th gift consists of aiai candies and bibi oranges.

你又n个礼物,全都要分给孩子们。但你想让所有的孩子觉得公平,所有你需要保证所有的礼物全部相同。第i个礼物是一个有a[i]个糖和b[i]个橘子的蛋糕

During one move, you can choose some gift 1≤i≤n1≤i≤n and do one of the following operations:

每一步,你可以选择一个礼物并进行以下任意操作

  • eat exactly one candy from this gift (decrease aiai by one);
  • eat exactly one orange from this gift (decrease bibi by one);
  • eat exactly one candy and exactly one orange from this gift (decrease both aiai and bibi by one).
  • 吃掉1个糖
  • 吃掉1个橘子
  • 吃掉1个橘子和1个糖

Of course, you can not eat a candy or orange if it's not present in the gift (so neither aiai nor bibi can become less than zero).

当然,你不能吃不存在的糖或橘子(橘子和糖的数量不能为负)。

As said above, all gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: a1=a2=⋯=ana1=a2=⋯=an and b1=b2=⋯=bnb1=b2=⋯=bn (and aiai equals bibi is not necessary).

如上所说,所有的礼物必须相同。即a数组全部最后得完全相等,b数组也是。

Your task is to find the minimum number of moves required to equalize all the given gifts.

你的工作就是看要至少多少步操作

You have to answer tt independent test cases.

有多个输入数据

Input

The first line of the input contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Then tt test cases follow.

The first line of the test case contains one integer nn (1≤n≤501≤n≤50) — the number of gifts. The second line of the test case contains nnintegers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the number of candies in the ii-th gift. The third line of the test case contains nnintegers b1,b2,…,bnb1,b2,…,bn (1≤bi≤1091≤bi≤109), where bibi is the number of oranges in the ii-th gift.

Output

For each test case, print one integer: the minimum number of moves required to equalize all the given gifts.

Example
input
Copy
5
3
3 5 6
3 2 3
5
1 2 3 4 5
5 4 3 2 1
3
1 1 1
2 2 2
6
1 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1
3
10 12 8
7 5 4
output
Copy
6
16
0
4999999995
7
Note

In the first test case of the example, we can perform the following sequence of moves:

  • choose the first gift and eat one orange from it, so a=[3,5,6]a=[3,5,6] and b=[2,2,3]b=[2,2,3];
  • choose the second gift and eat one candy from it, so a=[3,4,6]a=[3,4,6] and b=[2,2,3]b=[2,2,3];
  • choose the second gift and eat one candy from it, so a=[3,3,6]a=[3,3,6] and b=[2,2,3]b=[2,2,3];
  • choose the third gift and eat one candy and one orange from it, so a=[3,3,5]a=[3,3,5] and b=[2,2,2]b=[2,2,2];
  • choose the third gift and eat one candy from it, so a=[3,3,4]a=[3,3,4] and b=[2,2,2]b=[2,2,2];
  • choose the third gift and eat one candy from it, so a=[3,3,3]a=[3,3,3] and b=[2,2,2]b=[2,2,2].
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define DEBUG if(1)
#define MAXN 100
#define REP(i,b,e) for(int i=b;i<e;i++)
long long list[2][MAXN],ln;//数会很大
int main(){
    int CASE;cin>>CASE;
    while(CASE--){
        long long minab[2];
        cin>>ln;
        REP(ab,0,2){
            cin>>list[ab][0];
            minab[ab]=list[ab][0];、
            REP(i,1,ln){
                cin>>list[ab][i];
                //先接受输入
                minab[ab]=min(minab[ab],list[ab][i]);
                然后找出当前数组最小的
            }
        }
        long long ta,tb,total=0;
        REP(i,0,ln){
            ta=list[0][i]-minab[0];
            tb=list[1][i]-minab[1];
            total+=max(ta,tb);
            //看每一个蛋糕减少到最少需要至少多少步,全加起来
        }
        cout<<total<<endl;
    }

    return 0;
}

 

posted on 2020-08-09 21:49  forwhat00  阅读(0)  评论(0)    收藏  举报