题目描述
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.
input
4
3 2
1 2 3
4 5
2 3
1 2
3 4 5
1 1
100
1
5 3
1 1 1 1 1
1000000000 1000000000 1000000000
output
12
9
1
3000000002
翻译
Kiyora有n块白板,编号从1到n。最初,第i块白板上写有整数ai。
Koxia进行了m个操作。第j次操作是选择其中一块白板,将写在上面的整数改为bj。
在进行完所有m次操作后,找出写在白板上的整数的最大可能之和。
输入
每个测试由多个测试案例组成。第一行包含一个整数t(1≤t≤1000)--测试案例的数量。测试用例的描述如下。
每个测试用例的第一行包含两个整数n和m(1≤n,m≤100)。
每个测试用例的第二行包含n个整数a1,a2,...,an(1≤ai≤109)。
每个测试用例的第三行包含m个整数b1,b2,...,bm(1≤bi≤109)。
输出
对于每个测试用例,输出一个单一的整数--执行所有m个操作后写在白板上的最大可能的整数之和。
题意:数组a有n个数,数组b有m个数,经过m次操作把数组b的数给数组a里的m个数替换
思路:对a数组排序然后把b数组的数给a[ 1 ] 再对a数组排序直到b数组里的数全部替换给a
代码
#include<iostream>
using namespace std;
#include<cstring>
#include<algorithm>
#define ll long long
const ll N=1e4;
ll a[N];
ll b[N];
int main()
{
int t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>b[i];
sort(a+1,a+1+n);
for(int i=1;i<=m;i++)
{
a[1]=b[i];
sort(a+1,a+1+n);
}
ll sum=0;
for(int i=1;i<=n;i++)
{
sum+=a[i];
}
cout<<sum<<endl;
memset(a,0,sizeof a);
memset(b,0,sizeof b);
}
return 0;
}