A. Koxia and Whiteboards

 原题

Kiyora has nn whiteboards numbered from 11 to nn. Initially, the ii-th whiteboard has the integer aiai 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 bjbj.

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

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001≤t≤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 (1≤n,m≤1001≤n,m≤100).

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

The third line of each test case contains mm integers b1,b2,…,bmb1,b2,…,bm (1≤bi≤1091≤bi≤109).

Output

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

题目大意

Kiyora 有n块白板,从1到n编号。初始情况下, 第i块白板上写着一个整数ai 

  。 Koxia 要进行m次操作。第j jj次操作是,选择一块白板并将上面的整数修改为bj

 。 计算全部m次操作后所有白板上数字之和的最大可能值。
就是将小数替换为大数

代码如下


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		ll a[110];
		ll b[110];
		for(int i=1;i<=n;i++) cin>>a[i];
		sort(a+1,a+1+n);
		for(int i=1;i<=m;i++) 
		{
			cin>>b[i];
			a[1]=b[i];
        //现在把最小的换为b[i]
			sort(a+1,a+1+n);
		}
		ll sum=0;
        //求a数组的最大和
		for(int i=1;i<=n;i++) sum+=a[i];
		cout<<sum<<endl;
	}
	return 0;
 } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值