-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
46 lines (45 loc) · 778 Bytes
/
B.cpp
File metadata and controls
46 lines (45 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
using namespace std;
void sum(int n,int k,vector <int> a,vector <int> b)
{
int s=0,i=0;
sort(a.begin(),a.end());
sort(b.begin(),b.end());
while(i<n)
{
if(b[n-1-i]>a[i] && k>0)
{
s+=b[n-1-i];
k--;
}
else
{
s+=a[i];
}
i++;
}
cout<<s<<endl;
}
int main()
{
int t,n,k;
cin>>t;
//vector<int> a(n);
//vector <int> b;
for(int i=0;i<t;i++)
{
cin>>n>>k;
vector <int> a(n);
vector <int> b(n);
for(int j=0;j<n;j++)
{
cin>>a[j];
}
for(int k=0;k<n;k++)
{
cin>>b[k];
}
sum(n,k,a,b);
}
return 0;
}