Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n,k,sum=0;
- cin>>n>>k;
- int arr1[n];
- int arr2[n];
- for(int i=0;i<n;i++)
- {
- cin>>arr1[i];
- }
- for(int j=0;j<n;j++)
- {
- cin>>arr2[j];
- }
- if(k==0)
- {
- cout<< accumulate(arr1, arr1+n,sum)<<endl;;
- }
- else{
- sort(arr1,arr1+n);
- sort(arr2, arr2 + n, greater<int>());
- for(int i=0;i<k;i++)
- {
- if(arr1[i]<arr2[i])
- {
- arr1[i]=arr2[i];
- }
- }
- cout<<accumulate(arr1, arr1+n,sum)<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement