原题
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;
}