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
int main(){
// freopen("a.in", "r", stdin);
cin.tie(0)->sync_with_stdio(0);
int n, m; cin >> n >> m;
vector<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];
for(int i = 0; i<n; ++i) a[i] = max(a[i], b[i]);
ll lo = 0, hi = 1e18;
while(lo<hi){
ll mid = lo+(hi-lo+1)/2;
ll cnt = 0;
for(int i = 0; i<n; ++i){
if(a[i]*m>=mid) cnt += m-(mid+a[i]-1)/a[i];
else cnt -= (mid-a[i]*m+b[i]-1)/b[i];
if(cnt<-1ll*n*m) break;
}
if(cnt>=0ll) lo = mid;
else hi = mid-1;
}
cout << lo << '\n';
}
# | 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... |