Skip to content

Commit a6303ec

Browse files
committed
Added 1353B - Two Arrays And Swaps.cpp
1 parent d93c889 commit a6303ec

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

1353B - Two Arrays And Swaps.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ॐ नमः शिवाय
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
#define ll long long
5+
6+
// Code Written By: Vikash Patel
7+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
8+
9+
int main()
10+
{
11+
int t;
12+
cin>>t;
13+
while(t--)
14+
{
15+
int n,k;
16+
cin>>n>>k;
17+
int a[n], b[n];
18+
for(int i=0;i<n;i++)
19+
{
20+
cin>>a[i];
21+
}
22+
for(int i=0;i<n;i++)
23+
{
24+
cin>>b[i];
25+
}
26+
sort(a,a+n);
27+
sort(b,b+n, greater<int>());
28+
int maxSum = 0;
29+
for(int i=0;i<k;i++)
30+
{
31+
if(a[i]>b[i])
32+
maxSum += a[i];
33+
else
34+
maxSum += b[i];
35+
}
36+
for(int i=k;i<n;i++)
37+
{
38+
maxSum += a[i];
39+
}
40+
cout<<maxSum<<endl;
41+
}
42+
return 0;
43+
}

0 commit comments

Comments
 (0)