-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht1.cpp
More file actions
44 lines (40 loc) · 646 Bytes
/
t1.cpp
File metadata and controls
44 lines (40 loc) · 646 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
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main()
{
int n, k;
cin>>n>>k;
int k1 = k;
long long int a[n], b[n], a1[n], b1[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
a1[i] = a[i];
}
for(int i=0; i<n; i++)
{
cin>>b[i];
b1[i] = b[i];
}
sort(a, a+n);
sort(b, b+n);
sort(a1, a1+n);
sort(b1, b1+n);
long long int ans = a[n-1] + b[n-1];
while(k-- && a[n-1]>b[0])
{
swap(a[n-1], b[0]);
sort(a, a+n);
sort(b, b+n);
}
while(k1-- && b1[n-1]>a1[0])
{
swap(b1[n-1], a1[0]);
sort(a1, a1+n);
sort(b1, b1+n);
}
ans = min(ans, min(a[n-1]+b[n-1], a1[n-1] + b1[n-1]));
cout<<ans;
return 0;
}