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;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
ll n, m;
cin >> n >> m;
ll 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(m==1) {
ll ans = (ll)1<<60;
for(int i=0;i<n; i++) {
ans = min(ans, max(a[i], b[i]));
}
cout << ans;
return 0;
}
ll lo = 0, hi = (ll)1<<60;
while(hi-lo>1) {
ll x = (lo+hi)/2;
ll ans = 0;
for(int i=0; i<n; i++) {
if(a[i]>b[i]){
if(x > m*a[i]) ans += m + (x-a[i]*m+b[i]-1)/b[i];
else ans += (x+a[i]-1)/a[i];
}
else ans += (x+b[i]-1)/b[i];
}
if(ans <= n*m) lo = x;
else hi = x;
}
cout << lo;
}
# | 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... |