CF1353B.Two Arrays And Swaps
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays a and b both consisting of n positive (greater than zero) integers. You are also given an integer k.
In one move, you can choose two indices i and j (1≤i,j≤n) and swap ai and bj (i.e. ai becomes bj and vice versa). Note that i and j can be equal or different (in particular, swap a2 with b2 or swap a3 and b9 both are acceptable moves).
Your task is to find the maximum possible sum you can obtain in the array a if you can do no more than (i.e. at most) k such moves (swaps).
You have to answer t independent test cases.
给你两个数组 a 和 b,它们均包含 n 个正整数(即大于零的整数)。同时给你一个整数 k。
在一次操作中,你可以选择两个下标 i 和 j(满足 1≤i,j≤n),并交换 ai 与 bj(即 ai 变为 bj,bj 变为 ai)。注意:i 和 j 可以相等,也可以不同(例如,交换 a2 与 b2,或交换 a3 与 b9,均是合法的操作)。
你的任务是:在最多进行 k 次此类交换操作(即交换次数不超过 k)的前提下,求出数组 a 中元素之和的最大可能值。
你需要回答 t 个相互独立的测试用例。
输入格式
The first line of the input contains one integer t (1≤t≤200) — the number of test cases. Then t test cases follow.
The first line of the test case contains two integers n and k (1≤n≤30;0≤k≤n) — the number of elements in a and b and the maximum number of moves you can do. The second line of the test case contains n integers a1,a2,…,an (1≤ai≤30), where ai is the i-th element of a. The third line of the test case contains n integers b1,b2,…,bn (1≤bi≤30), where bi is the i-th element of b.
输入的第一行包含一个整数 t(1≤t≤200),表示测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤30;0≤k≤n),分别表示数组 a 和 b 的元素个数,以及你最多可以执行的操作次数。每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤30),其中 ai 是数组 a 的第 i 个元素。每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤30),其中 bi 是数组 b 的第 i 个元素。
输出格式
For each test case, print the answer — the maximum possible sum you can obtain in the array a if you can do no more than (i.e. at most) k swaps.
对于每个测试用例,输出答案——即在最多进行 k 次交换的前提下,数组 a 中所能得到的最大可能和。
输入输出样例
输入#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=1 and b2=4, so a=[4,2] and 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=1 and b1=10, a3=3 and b3=10 and a2=2 and b4=10, so a=[10,10,10,4,5] and 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 a and b, so a=[4,4,5,4] and b=[1,2,2,1].
在示例的第一个测试用例中,你可以交换 a1=1 和 b2=4,从而得到 a=[4,2] 和 b=[3,1]。
在示例的第二个测试用例中,你无需进行任何交换。
在示例的第三个测试用例中,你可以交换 a1=1 和 b1=10、a3=3 和 b3=10,以及 a2=2 和 b4=10,从而得到 a=[10,10,10,4,5] 和 b=[1,9,3,2,9]。
在示例的第四个测试用例中,你无法进行任何交换。
在示例的第五个测试用例中,你可以交换整个数组 a 和 b,从而得到 a=[4,4,5,4] 和 b=[1,2,2,1]。
输入解题思路,AI测评打分。不知道怎么写?