CF1399B.Gifts Fixing

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aia_i candies and bib_i oranges.

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

  • eat exactly one candy from this gift (decrease aia_i by one);
  • eat exactly one orange from this gift (decrease bib_i by one);
  • eat exactly one candy and exactly one orange from this gift (decrease both aia_i and bib_i by one).

Of course, you can not eat a candy or orange if it's not present in the gift (so neither aia_i nor bib_i 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=⋯=ana_1 = a_2 = \dots = a_n and b1=b2=⋯=bnb_1 = b_2 = \dots = b_n (and aia_i equals bib_i is not necessary).

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.

你有 nn 件礼物,希望将它们全部分给孩子们。当然,你不想让任何人感到被冒犯,因此所有礼物之间必须完全相同。第 ii 件礼物包含 aia_i 颗糖果和 bib_i 个橙子。

在一次操作中,你可以选择某一件礼物 1≤i≤n1 \le i \le n,并执行以下三种操作之一:

  • 从该礼物中恰好吃掉一颗糖果(即令 aia_i 减少 1);
  • 从该礼物中恰好吃掉一个橙子(即令 bib_i 减少 1);
  • 从该礼物中恰好吃掉一颗糖果和一个橙子(即同时令 aia_i 和 bib_i 各减少 1)。

当然,你不能吃掉不存在的糖果或橙子(即 aia_i 和 bib_i 均不能变为负数)。

如前所述,所有礼物必须变得完全相同。这意味着经过若干次操作后,需满足如下两个条件:a1=a2=⋯=ana_1 = a_2 = \dots = a_n 且 b1=b2=⋯=bnb_1 = b_2 = \dots = b_n(注意:不要求对任意 ii 都有 ai=bia_i = b_i)。

你的任务是求出使所有给定礼物变得相同的最少操作次数。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤10001 \le t \le 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 \le n \le 50) — the number of gifts. The second line of the test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i is the number of candies in the ii-th gift. The third line of the test case contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (1≤bi≤1091 \le b_i \le 10^9), where bib_i is the number of oranges in the ii-th gift.

输入的第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。接下来是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤501 \le n \le 50),表示礼物的数量。
每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9),其中 aia_i 表示第 ii 个礼物中的糖果数量。
每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤1091 \le b_i \le 10^9),其中 bib_i 表示第 ii 个礼物中的橘子数量。

输出格式

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

对于每个测试用例,输出一个整数:使所有给定礼物相等所需的最少移动次数。

输入输出样例

  • 输入#1

    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

    输出#1

    6
    16
    0
    4999999995
    7

说明/提示

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].

在示例的第一个测试用例中,我们可以执行以下操作序列:

  • 选择第一个礼物并从中吃掉一个橘子,此时 a=[3,5,6]a = [3, 5, 6],b=[2,2,3]b = [2, 2, 3];
  • 选择第二个礼物并从中吃掉一颗糖果,此时 a=[3,4,6]a = [3, 4, 6],b=[2,2,3]b = [2, 2, 3];
  • 选择第二个礼物并从中吃掉一颗糖果,此时 a=[3,3,6]a = [3, 3, 6],b=[2,2,3]b = [2, 2, 3];
  • 选择第三个礼物并从中各吃掉一颗糖果和一个橘子,此时 a=[3,3,5]a = [3, 3, 5],b=[2,2,2]b = [2, 2, 2];
  • 选择第三个礼物并从中吃掉一颗糖果,此时 a=[3,3,4]a = [3, 3, 4],b=[2,2,2]b = [2, 2, 2];
  • 选择第三个礼物并从中吃掉一颗糖果,此时 a=[3,3,3]a = [3, 3, 3],b=[2,2,2]b = [2, 2, 2]。

输入解题思路,AI测评打分。不知道怎么写?

首页