codeforces 1770A. Koxia and Whiteboards

A. Koxia and Whiteboards
Kiyora has n whiteboards numbered from 1 to n. Initially, the i-th whiteboard has the integer ai written on it.

Koxia performs m operations. The j-th operation is to choose one of the whiteboards and change the integer written on it to bj.

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

Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers n and m (1≤n,m≤100).

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

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

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

Example
inputCopy
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
outputCopy
12
9
1
3000000002
Note
In the first test case, Koxia can perform the operations as follows:

Choose the 1-st whiteboard and rewrite the integer written on it to b1=4.
Choose the 2-nd whiteboard and rewrite to b2=5.
After performing all operations, the numbers on the three whiteboards are 4, 5 and 3 respectively, and their sum is 12. It can be proven that this is the maximum possible sum achievable.

In the second test case, Koxia can perform the operations as follows:

Choose the 2-nd whiteboard and rewrite to b1=3.
Choose the 1-st whiteboard and rewrite to b2=4.
Choose the 2-nd whiteboard and rewrite to b3=5.
The sum is 4+5=9. It can be proven that this is the maximum possible sum achievable.

//2023见!!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> c(n),b(m);
    priority_queue<int,vector<int>,greater<int>> heap;
    for(int i=0;i<n;i++){cin>>c[i];heap.push(c[i]);}
    for(int i=0;i<m;i++){cin>>b[i];}
    for(int i=0;i<m;i++){
        auto t=heap.top();
        heap.pop();
        heap.push(b[i]);
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        auto t=heap.top();
        sum+=t;
        heap.pop();
    }
    cout<<sum<<endl;
}
int main(void){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值