#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
vector <int> a(n),b(n);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
if(m==1){
int res=1e9;
for(int i=0;i<n;i++){
res=min(res,max(a[i],b[i]));
}
cout<<res<<"\n";
}
else{
set <pair <int,int> > st;
for(int i=0;i<n;i++){
st.insert({max(a[i],b[i]),i});
}
for(int i=0;i<m*n-n;i++){
int x=st.begin()->ff;
int id=st.begin()->ss;
st.erase(st.begin());
x+=max(a[id],b[id]);
st.insert({x,id});
}
cout<<st.begin()->ff<<"\n";
}
}
/*
4 25
1 2 3 4
1 2 3 4
3 3
19 4 5
2 6 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
5136 KB |
Output is correct |
12 |
Correct |
38 ms |
4956 KB |
Output is correct |
13 |
Correct |
32 ms |
4956 KB |
Output is correct |
14 |
Correct |
35 ms |
4952 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
19 ms |
5164 KB |
Output is correct |
17 |
Correct |
40 ms |
4956 KB |
Output is correct |
18 |
Correct |
38 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
19 ms |
5164 KB |
Output is correct |
3 |
Correct |
40 ms |
4956 KB |
Output is correct |
4 |
Correct |
38 ms |
4956 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
664 KB |
Output is correct |
13 |
Correct |
86 ms |
15012 KB |
Output is correct |
14 |
Correct |
60 ms |
10064 KB |
Output is correct |
15 |
Correct |
37 ms |
7760 KB |
Output is correct |
16 |
Correct |
58 ms |
6304 KB |
Output is correct |
17 |
Correct |
18 ms |
348 KB |
Output is correct |
18 |
Correct |
13 ms |
452 KB |
Output is correct |
19 |
Correct |
10 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
464 KB |
Output is correct |
21 |
Correct |
7 ms |
344 KB |
Output is correct |
22 |
Correct |
27 ms |
840 KB |
Output is correct |
23 |
Correct |
27 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
5136 KB |
Output is correct |
12 |
Correct |
38 ms |
4956 KB |
Output is correct |
13 |
Correct |
32 ms |
4956 KB |
Output is correct |
14 |
Correct |
35 ms |
4952 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
456 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
664 KB |
Output is correct |
23 |
Correct |
86 ms |
15012 KB |
Output is correct |
24 |
Correct |
60 ms |
10064 KB |
Output is correct |
25 |
Correct |
37 ms |
7760 KB |
Output is correct |
26 |
Correct |
58 ms |
6304 KB |
Output is correct |
27 |
Correct |
18 ms |
348 KB |
Output is correct |
28 |
Correct |
13 ms |
452 KB |
Output is correct |
29 |
Correct |
10 ms |
348 KB |
Output is correct |
30 |
Correct |
6 ms |
464 KB |
Output is correct |
31 |
Correct |
7 ms |
344 KB |
Output is correct |
32 |
Correct |
27 ms |
840 KB |
Output is correct |
33 |
Correct |
27 ms |
860 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
19 ms |
5164 KB |
Output is correct |
36 |
Correct |
40 ms |
4956 KB |
Output is correct |
37 |
Correct |
38 ms |
4956 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
664 KB |
Output is correct |
9 |
Correct |
86 ms |
15012 KB |
Output is correct |
10 |
Correct |
60 ms |
10064 KB |
Output is correct |
11 |
Correct |
37 ms |
7760 KB |
Output is correct |
12 |
Correct |
58 ms |
6304 KB |
Output is correct |
13 |
Correct |
18 ms |
348 KB |
Output is correct |
14 |
Correct |
13 ms |
452 KB |
Output is correct |
15 |
Correct |
10 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
464 KB |
Output is correct |
17 |
Correct |
7 ms |
344 KB |
Output is correct |
18 |
Correct |
27 ms |
840 KB |
Output is correct |
19 |
Correct |
27 ms |
860 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
19 ms |
5164 KB |
Output is correct |
22 |
Correct |
40 ms |
4956 KB |
Output is correct |
23 |
Correct |
38 ms |
4956 KB |
Output is correct |
24 |
Execution timed out |
1045 ms |
4956 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
5136 KB |
Output is correct |
12 |
Correct |
38 ms |
4956 KB |
Output is correct |
13 |
Correct |
32 ms |
4956 KB |
Output is correct |
14 |
Correct |
35 ms |
4952 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
456 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
664 KB |
Output is correct |
23 |
Correct |
86 ms |
15012 KB |
Output is correct |
24 |
Correct |
60 ms |
10064 KB |
Output is correct |
25 |
Correct |
37 ms |
7760 KB |
Output is correct |
26 |
Correct |
58 ms |
6304 KB |
Output is correct |
27 |
Correct |
18 ms |
348 KB |
Output is correct |
28 |
Correct |
13 ms |
452 KB |
Output is correct |
29 |
Correct |
10 ms |
348 KB |
Output is correct |
30 |
Correct |
6 ms |
464 KB |
Output is correct |
31 |
Correct |
7 ms |
344 KB |
Output is correct |
32 |
Correct |
27 ms |
840 KB |
Output is correct |
33 |
Correct |
27 ms |
860 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |