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() {
cin.tie(0); ios_base::sync_with_stdio(0);
ll 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]);
auto ok = [&](ll x) -> bool {
ll left = 0;
for(int i = 0; i < n; i++) {
ll z = (x + a[i] - 1) / a[i];
if(z < m) {
left += m - z;
} else {
left -= (x - a[i] * m + b[i] - 1) / b[i];
}
}
return left >= 0;
};
ll l = 0, r = 1e15, ans = 0;
while(l <= r) {
ll mid = (l + r) / 2;
if(ok(mid)) {
l = mid + 1, ans = mid;
} else {
r = mid - 1;
}
}
cout << ans << '\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... |