CF1353B.Two Arrays And Swaps

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two arrays aa and bb both consisting of nn positive (greater than zero) integers. You are also given an integer kk.

In one move, you can choose two indices ii and jj (1≤i,j≤n1 \le i, j \le n) and swap aia_i and bjb_j (i.e. aia_i becomes bjb_j and vice versa). Note that ii and jj can be equal or different (in particular, swap a2a_2 with b2b_2 or swap a3a_3 and b9b_9 both are acceptable moves).

Your task is to find the maximum possible sum you can obtain in the array aa if you can do no more than (i.e. at most) kk such moves (swaps).

You have to answer tt independent test cases.

给你两个数组 aa 和 bb,它们均包含 nn 个正整数(即大于零的整数)。同时给你一个整数 kk。

在一次操作中,你可以选择两个下标 ii 和 jj(满足 1≤i,j≤n1 \le i, j \le n),并交换 aia_i 与 bjb_j(即 aia_i 变为 bjb_j,bjb_j 变为 aia_i)。注意:ii 和 jj 可以相等,也可以不同(例如,交换 a2a_2 与 b2b_2,或交换 a3a_3 与 b9b_9,均是合法的操作)。

你的任务是:在最多进行 kk 次此类交换操作(即交换次数不超过 kk)的前提下,求出数组 aa 中元素之和的最大可能值。

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

输入格式

The first line of the input contains one integer tt (1≤t≤2001 \le t \le 200) — the number of test cases. Then tt test cases follow.

The first line of the test case contains two integers nn and kk (1≤n≤30;0≤k≤n1 \le n \le 30; 0 \le k \le n) — the number of elements in aa and bb and the maximum number of moves you can do. The second line of the test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤301 \le a_i \le 30), where aia_i is the ii-th element of aa. The third line of the test case contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (1≤bi≤301 \le b_i \le 30), where bib_i is the ii-th element of bb.

输入的第一行包含一个整数 tt(1≤t≤2001 \le t \le 200),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤301 \le n \le 30;0≤k≤n0 \le k \le n),分别表示数组 aa 和 bb 的元素个数,以及你最多可以执行的操作次数。每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤301 \le a_i \le 30),其中 aia_i 是数组 aa 的第 ii 个元素。每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤301 \le b_i \le 30),其中 bib_i 是数组 bb 的第 ii 个元素。

输出格式

For each test case, print the answer — the maximum possible sum you can obtain in the array aa if you can do no more than (i.e. at most) kk swaps.

对于每个测试用例,输出答案——即在最多进行 kk 次交换的前提下,数组 aa 中所能得到的最大可能和。

输入输出样例

  • 输入#1

    5
    2 1
    1 2
    3 4
    5 5
    5 5 6 6 5
    1 2 5 4 3
    5 3
    1 2 3 4 5
    10 9 10 10 9
    4 0
    2 2 4 3
    2 4 2 3
    4 4
    1 2 2 1
    4 4 5 4

    输出#1

    6
    27
    39
    11
    17

说明/提示

In the first test case of the example, you can swap a1=1a_1 = 1 and b2=4b_2 = 4, so a=[4,2]a=[4, 2] and b=[3,1]b=[3, 1].

In the second test case of the example, you don't need to swap anything.

In the third test case of the example, you can swap a1=1a_1 = 1 and b1=10b_1 = 10, a3=3a_3 = 3 and b3=10b_3 = 10 and a2=2a_2 = 2 and b4=10b_4 = 10, so a=[10,10,10,4,5]a=[10, 10, 10, 4, 5] and b=[1,9,3,2,9]b=[1, 9, 3, 2, 9].

In the fourth test case of the example, you cannot swap anything.

In the fifth test case of the example, you can swap arrays aa and bb, so a=[4,4,5,4]a=[4, 4, 5, 4] and b=[1,2,2,1]b=[1, 2, 2, 1].

在示例的第一个测试用例中,你可以交换 a1=1a_1 = 1 和 b2=4b_2 = 4,从而得到 a=[4,2]a=[4, 2] 和 b=[3,1]b=[3, 1]。

在示例的第二个测试用例中,你无需进行任何交换。

在示例的第三个测试用例中,你可以交换 a1=1a_1 = 1 和 b1=10b_1 = 10、a3=3a_3 = 3 和 b3=10b_3 = 10,以及 a2=2a_2 = 2 和 b4=10b_4 = 10,从而得到 a=[10,10,10,4,5]a=[10, 10, 10, 4, 5] 和 b=[1,9,3,2,9]b=[1, 9, 3, 2, 9]。

在示例的第四个测试用例中,你无法进行任何交换。

在示例的第五个测试用例中,你可以交换整个数组 aa 和 bb,从而得到 a=[4,4,5,4]a=[4, 4, 5, 4] 和 b=[1,2,2,1]b=[1, 2, 2, 1]。

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

首页