#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;
bool s=1;
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(a[i]!=b[i])s=0;
}
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 if(s){
int l=0,r=1e18;
while(l<=r){
int md=(l+r)/2;
int sum=0;
for(int i=0;i<n;i++){
sum+=(md+(a[i]-1))/a[i];
}
if(sum<=n*m)l=md+1;
else r=md-1;
}
cout<<r<<"\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";
for(auto x : st){
cout<<x.ff<<" "<<x.ss<<'\n';
}
}
}
/*
4 25
1 2 3 4
1 2 3 4
12 6 3 4
3 3
19 4 5
2 6 2
5 60000
630510219 369411957 874325200 990002527 567203997
438920902 634940661 593780254 315929832 420627496
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
456 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
49 ms |
8068 KB |
Output is correct |
12 |
Correct |
48 ms |
8192 KB |
Output is correct |
13 |
Correct |
34 ms |
6996 KB |
Output is correct |
14 |
Correct |
35 ms |
6992 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
23 ms |
5912 KB |
Output is correct |
17 |
Correct |
46 ms |
8532 KB |
Output is correct |
18 |
Correct |
45 ms |
8052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
5912 KB |
Output is correct |
3 |
Correct |
46 ms |
8532 KB |
Output is correct |
4 |
Correct |
45 ms |
8052 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 |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
452 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
42 ms |
4520 KB |
Output is correct |
14 |
Correct |
28 ms |
3156 KB |
Output is correct |
15 |
Correct |
22 ms |
2896 KB |
Output is correct |
16 |
Correct |
17 ms |
2140 KB |
Output is correct |
17 |
Correct |
1 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 |
344 KB |
Output is correct |
22 |
Incorrect |
1 ms |
548 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
456 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
49 ms |
8068 KB |
Output is correct |
12 |
Correct |
48 ms |
8192 KB |
Output is correct |
13 |
Correct |
34 ms |
6996 KB |
Output is correct |
14 |
Correct |
35 ms |
6992 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 |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
452 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
42 ms |
4520 KB |
Output is correct |
24 |
Correct |
28 ms |
3156 KB |
Output is correct |
25 |
Correct |
22 ms |
2896 KB |
Output is correct |
26 |
Correct |
17 ms |
2140 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Incorrect |
1 ms |
548 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
42 ms |
4520 KB |
Output is correct |
10 |
Correct |
28 ms |
3156 KB |
Output is correct |
11 |
Correct |
22 ms |
2896 KB |
Output is correct |
12 |
Correct |
17 ms |
2140 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
18 |
Incorrect |
1 ms |
548 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
456 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
49 ms |
8068 KB |
Output is correct |
12 |
Correct |
48 ms |
8192 KB |
Output is correct |
13 |
Correct |
34 ms |
6996 KB |
Output is correct |
14 |
Correct |
35 ms |
6992 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 |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
452 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
42 ms |
4520 KB |
Output is correct |
24 |
Correct |
28 ms |
3156 KB |
Output is correct |
25 |
Correct |
22 ms |
2896 KB |
Output is correct |
26 |
Correct |
17 ms |
2140 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Incorrect |
1 ms |
548 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |