We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d93c889 commit a6303ecCopy full SHA for a6303ec
1353B - Two Arrays And Swaps.cpp
@@ -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
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
39
40
+ cout<<maxSum<<endl;
41
42
+ return 0;
43
+}
0 commit comments