题意:

给定两个数组,你可以交换 k 次 两个数组的元素,问最后 a 数组的和最大可以是多少?

题目:

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.

Input

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.

Output

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.

Example

Input

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

Output

6
27
39
11
17

Note

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

分析:

将两个数组sort排序后,分别取前k个,后k个进行比较,如果能使答案变优即可以贪心,交换即可。

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[35],b[35];
int t,n,k;
int main()
{scanf("%d",&t);while(t--){scanf("%d%d",&n,&k);int i,ans=0;for(i=1; i<=n; i++)scanf("%d",&a[i]);for(i=1; i<=n; i++)scanf("%d",&b[i]);sort(a+1,a+n+1);sort(b+1,b+n+1);for(i=1; i<=k; i++){if(a[i]>b[n-i+1])break;elseswap(a[i],b[n-i+1]);}for(i=1; i<=n; i++)ans+=a[i];printf("%d\n",ans);}return 0;
}

Two Arrays And Swaps CodeForces - 1353B(贪心+分类)相关推荐

  1. Two Arrays And Swaps

    文章目录 一.B. Two Arrays And Swaps 总结 一.B. Two Arrays And Swaps 本题链接:Two Arrays And Swaps 题目: B. Two Arr ...

  2. 贪心 ---- Codeforces Global Round 8,B. Codeforces Subsequences[贪心,贪的乘法原理]

    题目链接 给出字符串,统计子串(子串字母可以跳跃)是codeforces的数量. 本题要求,给出子串最少数量k,构造字符串s,要求字符串s包含的字母数量最少,输出这个最少的字符串s. 题目要求是至少有 ...

  3. CodeForces - 93B(贪心+vectorpairint,double +double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  4. Codeforces 985C (贪心)

    传送门 题面: C. Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Minimize the Permutation CodeForces - 1256(贪心)

    题意: q次询问,每次询问给你长度为n的排列,然后你每次可以选择一个位置i和i+1的数字进行交换.但是每个位置只能交换一次,问你反转若干次后,这个排列最小是多少? 题目: You are given ...

  6. Minimizing Difference CodeForces - 1244E(贪心题)

    题目 题意 官方题解: 百度翻译 思路 ac代码 题意 给出一列数,至多n个操作使其中的数+1或-1,要求得到最小的差值(最大值-最小值): You are given a sequence a1_{ ...

  7. Serval and Parenthesis Sequence CodeForces - 1153C 贪心

    题意:给出一个由"(",")","?"三种字符构成的序列,让我们把其中的问号替换成左右括号,使得整个序列变成一个完整地括号序列,也就是括号匹 ...

  8. Vasya and Multisets CodeForces - 1051C 模拟|分类讨论

    题意:把数组分成两个集合 每个集合中元素数量为1的个数相同(此个数可以是0) 分析: 这类问题就是要各种可能情况考虑到     然后分类讨论     完整地正确分类就AC     否则gg 如果数量为 ...

  9. CodeForces - 1089L 贪心

    The kingdom of Lazyland is the home to nn idlers. These idlers are incredibly lazy and create many p ...

最新文章

  1. SVN服务器搭建--Subversio与TortoiseSVN的配置安装
  2. java jdbc分页_使用JDBC进行分页查询
  3. 永远和靠谱的人在一起!
  4. Module build failed: ReferenceError: Unknown plugin module-resolver specified
  5. 一文讲透数据库,以后别说你不懂数据库
  6. 几种div/css布局的代码
  7. 员工入职是一连串事件(转)
  8. 【安全牛学习笔记】初识sql注入漏洞原理
  9. 500 内部服务器错误php,如何解决php 500内部服务器错误问题
  10. 从Android发展看Meego
  11. XP框架开启debug模式_推荐一个兼容性强完美支持XP框架的安卓模拟器,一直在用!...
  12. Clover 驱动文件夹_通过AppleALC,轻松解决苹果声卡驱动的问题.
  13. CV520直接pin对pin替换 MS520,直接替换,无需修改硬件以及软件
  14. 小猫爪:嵌入式小知识01-存储器
  15. cad绘制正八边形_什么是CAD?为什么要学CAD?该怎么学CAD?
  16. Map接口总结与HashMap源码分析
  17. 浙大计算机科学基础实验,想加实验室的看过来-浙大计算机实验室详细推介
  18. 人脸识别库face_recognition安装简单教程
  19. Python内置函数——getattr
  20. Tomcat连接数据库的方法

热门文章

  1. Android之提示A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
  2. Git撤销文件的修改(git checkout -- file)(git reset HEAD file)(git reset HEAD~)
  3. 第4章 字符串和格式化输入/输出
  4. 如何可以让球的时速达到100公里?
  5. 盘点这些年被黑的最惨的语言
  6. 世界上没有后悔药,时间匆匆,从关注它们开始......
  7. 和哪个专业的男生谈恋爱最惨?
  8. 用Python分析了20万场吃鸡数据,有不少有趣的发现
  9. 史上首次!世界杯使用视频裁判
  10. mysql select 反选_JQuery实现全选、全不选和反选功能