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>
#define int long long
#define x first
#define y second
#define pb push_back
using namespace std;
using pii=pair <int,int>;
using tii=pair <pii,int>;
void solve(){
int n,m;
cin>>n>>m;
int a[n+1],b[n+1];
for (int i=1; i<=n; i++) cin>>a[i];
for (int i=1; i<=n; i++) cin>>b[i];
int l=0,r=1e18;
while (l<r){
int mid=(l+r+1)/2;
int att=0,need=0;
for (int i=1; i<=n; i++){
if (a[i]<=b[i]){
need+=(mid+b[i]-1)/b[i];
} else {
int r=min(m,(mid+a[i]-1)/a[i]);
att+=r;
int nw=mid-a[i]*r;
if (nw>0) need+=(nw+b[i]-1)/b[i];
}
if (att+need>n*m) break;
}
if (att+need<=n*m) l=mid;
else r=mid-1;
}
cout<<l<<'\n';
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t=1;
//cin>>t;
while (t--) 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... |