//In the name of GOD
#include <bits/stdc++.h>
using namespace std;
const long long maxN=3e5+5;
long long n, m, a[maxN], b[maxN];
bool can(long long x){
long long cnt=0;
for (long long i=1; i<=n; i++){
cnt+=(a[i]<b[i] ? (x+b[i]-1)/b[i] : (m*a[i]>=x ? (x+a[i]-1)/a[i] : m+(x-m*a[i]+b[i]-1)/b[i]));
if(cnt>n*m) return false;
}
return true;
}
int main(){
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
cin >>n >>m;
for (long long i=1; i<=n; i++) cin >>a[i];
for (long long i=1; i<=n; i++) cin >>b[i];
long long l=0, r=LLONG_MAX;
while(r-l>1){
long long mid=(r>>1)+(l>>1);
if(can(mid)) l=mid;
else r=mid;
}
cout <<l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |