This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
ll a[300100];
ll b[300100];
ll n, m;
bool check(ll x){
ll h = 0;
//cout<<x<<' ';
for(int i=1; i<=n; i++){
if(a[i] > b[i]){
if(m * a[i] < x){
h += m;
h += (x - m * a[i] - 1) / b[i] + 1;
}
else{
h += (x - 1) / a[i] + 1;
}
}
else{
h += (x - 1) / b[i] + 1;
}
}
//cout<<h<<'\n';
return h <= m*n;
}
void solve(){
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>a[i];
}
for(int i=1; i<=n; i++){
cin>>b[i];
}
ll l=0, r=1e18;
while(l < r){
ll mid=(l+r)/2;
if(check(mid)) l = mid + 1;
else r = mid;
}
cout<<r - 1;
}
signed main(){
solve();
}
# | 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... |