#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll cdiv(ll a, ll b) {
return (a + b - 1) / b;
}
void solve() {
int n, m;
cin >> n >> m;
vector<ll> a(n), b(n);
for (auto &i: a) cin >> i;
for (auto &i: b) cin >> i;
for (int i = 0; i < n; i++) a[i] = max(a[i], b[i]);
// solve
auto check = [&](ll x) {
ll days = 0;
for (int i = 0; i < n; i++) {
if (x <= a[i] * m) days += cdiv(x, a[i]);
else days += m + cdiv(x - a[i] * m, b[i]);
if (days > n*m) return false;
}
return true;
};
ll l = 0, r = 1LL << 60;
while (r - l > 1) {
ll mid = (l + r) / 2;
if (check(mid)) l = mid;
else r = mid;
}
// ans
cout << l << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
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... |