#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;
vector <int> cnt(n);
for(int i=0;i<n;i++){
st.insert({max(a[i],b[i]),i});
if(a[i]>b[i])cnt[i]++;
}
for(int i=0;i<m*n-n;i++){
int x=st.begin()->ff;
int id=st.begin()->ss;
st.erase(st.begin());
if(a[id]>b[id] && cnt[id]<m){
x+=a[id];
cnt[id]++;
}
else x+=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
5 60000
630510219 369411957 874325200 990002527 567203997
438920902 634940661 593780254 315929832 420627496
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 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 |
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 |
48 ms |
5148 KB |
Output is correct |
12 |
Correct |
41 ms |
4956 KB |
Output is correct |
13 |
Correct |
32 ms |
4956 KB |
Output is correct |
14 |
Correct |
33 ms |
4952 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
24 ms |
4956 KB |
Output is correct |
17 |
Correct |
42 ms |
4952 KB |
Output is correct |
18 |
Correct |
45 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
24 ms |
4956 KB |
Output is correct |
3 |
Correct |
42 ms |
4952 KB |
Output is correct |
4 |
Correct |
45 ms |
4952 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 |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
13 |
Correct |
97 ms |
13192 KB |
Output is correct |
14 |
Correct |
69 ms |
9044 KB |
Output is correct |
15 |
Correct |
43 ms |
6748 KB |
Output is correct |
16 |
Correct |
71 ms |
5624 KB |
Output is correct |
17 |
Correct |
20 ms |
348 KB |
Output is correct |
18 |
Correct |
13 ms |
344 KB |
Output is correct |
19 |
Correct |
13 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
6 ms |
452 KB |
Output is correct |
22 |
Correct |
28 ms |
860 KB |
Output is correct |
23 |
Correct |
28 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 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 |
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 |
48 ms |
5148 KB |
Output is correct |
12 |
Correct |
41 ms |
4956 KB |
Output is correct |
13 |
Correct |
32 ms |
4956 KB |
Output is correct |
14 |
Correct |
33 ms |
4952 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
23 |
Correct |
97 ms |
13192 KB |
Output is correct |
24 |
Correct |
69 ms |
9044 KB |
Output is correct |
25 |
Correct |
43 ms |
6748 KB |
Output is correct |
26 |
Correct |
71 ms |
5624 KB |
Output is correct |
27 |
Correct |
20 ms |
348 KB |
Output is correct |
28 |
Correct |
13 ms |
344 KB |
Output is correct |
29 |
Correct |
13 ms |
348 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
31 |
Correct |
6 ms |
452 KB |
Output is correct |
32 |
Correct |
28 ms |
860 KB |
Output is correct |
33 |
Correct |
28 ms |
860 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
24 ms |
4956 KB |
Output is correct |
36 |
Correct |
42 ms |
4952 KB |
Output is correct |
37 |
Correct |
45 ms |
4952 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
38 ms |
1116 KB |
Output is correct |
46 |
Correct |
6 ms |
1368 KB |
Output is correct |
47 |
Correct |
6 ms |
348 KB |
Output is correct |
48 |
Correct |
32 ms |
5720 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
28 ms |
476 KB |
Output is correct |
51 |
Correct |
39 ms |
860 KB |
Output is correct |
52 |
Correct |
6 ms |
348 KB |
Output is correct |
53 |
Correct |
17 ms |
348 KB |
Output is correct |
54 |
Correct |
23 ms |
344 KB |
Output is correct |
55 |
Correct |
100 ms |
15956 KB |
Output is correct |
56 |
Correct |
69 ms |
10192 KB |
Output is correct |
57 |
Correct |
65 ms |
10324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
9 |
Correct |
97 ms |
13192 KB |
Output is correct |
10 |
Correct |
69 ms |
9044 KB |
Output is correct |
11 |
Correct |
43 ms |
6748 KB |
Output is correct |
12 |
Correct |
71 ms |
5624 KB |
Output is correct |
13 |
Correct |
20 ms |
348 KB |
Output is correct |
14 |
Correct |
13 ms |
344 KB |
Output is correct |
15 |
Correct |
13 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
452 KB |
Output is correct |
18 |
Correct |
28 ms |
860 KB |
Output is correct |
19 |
Correct |
28 ms |
860 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
24 ms |
4956 KB |
Output is correct |
22 |
Correct |
42 ms |
4952 KB |
Output is correct |
23 |
Correct |
45 ms |
4952 KB |
Output is correct |
24 |
Execution timed out |
1031 ms |
4440 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 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 |
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 |
48 ms |
5148 KB |
Output is correct |
12 |
Correct |
41 ms |
4956 KB |
Output is correct |
13 |
Correct |
32 ms |
4956 KB |
Output is correct |
14 |
Correct |
33 ms |
4952 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
23 |
Correct |
97 ms |
13192 KB |
Output is correct |
24 |
Correct |
69 ms |
9044 KB |
Output is correct |
25 |
Correct |
43 ms |
6748 KB |
Output is correct |
26 |
Correct |
71 ms |
5624 KB |
Output is correct |
27 |
Correct |
20 ms |
348 KB |
Output is correct |
28 |
Correct |
13 ms |
344 KB |
Output is correct |
29 |
Correct |
13 ms |
348 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
31 |
Correct |
6 ms |
452 KB |
Output is correct |
32 |
Correct |
28 ms |
860 KB |
Output is correct |
33 |
Correct |
28 ms |
860 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
38 ms |
1116 KB |
Output is correct |
42 |
Correct |
6 ms |
1368 KB |
Output is correct |
43 |
Correct |
6 ms |
348 KB |
Output is correct |
44 |
Correct |
32 ms |
5720 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
28 ms |
476 KB |
Output is correct |
47 |
Correct |
39 ms |
860 KB |
Output is correct |
48 |
Correct |
6 ms |
348 KB |
Output is correct |
49 |
Correct |
17 ms |
348 KB |
Output is correct |
50 |
Correct |
23 ms |
344 KB |
Output is correct |
51 |
Correct |
100 ms |
15956 KB |
Output is correct |
52 |
Correct |
69 ms |
10192 KB |
Output is correct |
53 |
Correct |
65 ms |
10324 KB |
Output is correct |
54 |
Execution timed out |
1031 ms |
4440 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |