#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;int m;
int ar[300005];
int br[300005];
int cr[300005];
int ok(int mi){
int lft=0;
for(int i=1;i<=n;i++){
int nd=(mi+ar[i]-1)/ar[i];
if(nd<=m){
cr[i]=0;
lft+=m-nd;
}else{
cr[i]=mi-ar[i]*m;
}
}
for(int i=1;i<=n;i++){
if(cr[i]==0){continue;}
lft-=(cr[i]+br[i]-1)/br[i];
}
if(lft>=0){return 1;}
return 0;
}
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>ar[i];
}
for(int i=1;i<=n;i++){
cin>>br[i];
ar[i]=max(ar[i],br[i]);
}
int l=1;int r=1e18;
while(l<r){
int mi=l+(r-l+1)/2;
if(ok(mi)){
l=mi;
}else{
r=mi-1;
}
}
cout<<l<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
9 ms |
468 KB |
Output is correct |
11 |
Correct |
451 ms |
8192 KB |
Output is correct |
12 |
Correct |
430 ms |
8284 KB |
Output is correct |
13 |
Correct |
378 ms |
8292 KB |
Output is correct |
14 |
Incorrect |
614 ms |
8288 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
208 ms |
4708 KB |
Output is correct |
10 |
Correct |
153 ms |
3608 KB |
Output is correct |
11 |
Correct |
113 ms |
2916 KB |
Output is correct |
12 |
Correct |
85 ms |
2672 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Incorrect |
11 ms |
452 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
9 ms |
468 KB |
Output is correct |
11 |
Correct |
451 ms |
8192 KB |
Output is correct |
12 |
Correct |
430 ms |
8284 KB |
Output is correct |
13 |
Correct |
378 ms |
8292 KB |
Output is correct |
14 |
Incorrect |
614 ms |
8288 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
208 ms |
4708 KB |
Output is correct |
10 |
Correct |
153 ms |
3608 KB |
Output is correct |
11 |
Correct |
113 ms |
2916 KB |
Output is correct |
12 |
Correct |
85 ms |
2672 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Incorrect |
11 ms |
452 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
9 ms |
468 KB |
Output is correct |
11 |
Correct |
451 ms |
8192 KB |
Output is correct |
12 |
Correct |
430 ms |
8284 KB |
Output is correct |
13 |
Correct |
378 ms |
8292 KB |
Output is correct |
14 |
Incorrect |
614 ms |
8288 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |