CF1770A.Koxia and Whiteboards

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Kiyora has nn whiteboards numbered from 11 to nn. Initially, the ii-th whiteboard has the integer aia_i written on it.

Koxia performs mm operations. The jj-th operation is to choose one of the whiteboards and change the integer written on it to bjb_j.

Find the maximum possible sum of integers written on the whiteboards after performing all mm operations.

Kiyora 有 nn 块白板,编号从 11nn。初始时,第 ii 块白板上写着整数 aia_i

Koxia 执行 mm 次操作。第 jj 次操作是选择其中一块白板,并将其上的整数改为 bjb_j

求执行完全部 mm 次操作后,所有白板上所写整数之和的最大可能值。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1t10001 \leq t \leq 1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn and mm (1n,m1001 \le n,m \le 100).

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9).

The third line of each test case contains mm integers b1,b2,,bmb_1, b_2, \ldots, b_m (1bi1091 \le b_i \le 10^9).

每个测试包含多个测试用例。第一行包含一个整数 tt1t10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nnmm1n,m1001 \le n,m \le 100)。

每个测试用例的第二行包含 nn 个整数 a1,a2,,ana_1, a_2, \ldots, a_n1ai1091 \le a_i \le 10^9)。

每个测试用例的第三行包含 mm 个整数 b1,b2,,bmb_1, b_2, \ldots, b_m1bi1091 \le b_i \le 10^9)。

输出格式

For each test case, output a single integer — the maximum possible sum of integers written on whiteboards after performing all mm operations.

对于每个测试用例,输出一个整数——执行全部 mm 次操作后,白板上所写整数之和的最大可能值。

输入输出样例

  • 输入#1

    4
    3 2
    1 2 3
    4 5
    2 3
    1 2
    3 4 5
    1 1
    100
    1
    5 3
    1 1 1 1 1
    1000000000 1000000000 1000000000

    输出#1

    12
    9
    1
    3000000002

说明/提示

In the first test case, Koxia can perform the operations as follows:

  1. Choose the 11-st whiteboard and rewrite the integer written on it to b1=4b_1=4.
  2. Choose the 22-nd whiteboard and rewrite to b2=5b_2=5.

After performing all operations, the numbers on the three whiteboards are 44, 55 and 33 respectively, and their sum is 1212. It can be proven that this is the maximum possible sum achievable.

In the second test case, Koxia can perform the operations as follows:

  1. Choose the 22-nd whiteboard and rewrite to b1=3b_1=3.
  2. Choose the 11-st whiteboard and rewrite to b2=4b_2=4.
  3. Choose the 22-nd whiteboard and rewrite to b3=5b_3=5.

The sum is 4+5=94 + 5 = 9. It can be proven that this is the maximum possible sum achievable.

在第一个测试用例中,Koxia 可以执行如下操作:

  1. 选择第 11 块白板,并将其上书写的整数重写为 b1=4b_1=4
  2. 选择第 22 块白板,并将其上书写的整数重写为 b2=5b_2=5

执行完所有操作后,三块白板上的数字分别为 445533,其和为 1212。可以证明这是所能达到的最大可能和。

在第二个测试用例中,Koxia 可以执行如下操作:

  1. 选择第 22 块白板,并将其上书写的整数重写为 b1=3b_1=3
  2. 选择第 11 块白板,并将其上书写的整数重写为 b2=4b_2=4
  3. 选择第 22 块白板,并将其上书写的整数重写为 b3=5b_3=5

其和为 4+5=94 + 5 = 9。可以证明这是所能达到的最大可能和。

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

首页