#include <bits/stdc++.h>
#define int long long
bool Check(std::vector<int>& a, std::vector<int>& b, int mid, int n, int m) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (m * a[i] < mid) {
// return false;
// assert((mid - (m * a[i]) + b[i] - 1) / b[i] >= 1);
cnt -= (mid - (m * a[i]) + b[i] - 1) / b[i];
assert(cnt < 0);
} else {
int need = (mid + a[i] - 1) / a[i];
need = m - need;
// assert(need >= 0);
assert(need == 0);
cnt += need;
}
}
return (cnt >= 0);
}
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n, m;
std::cin >> n >> m;
int min = 1e18;
std::vector<int> a(n);
std::vector<int> b(n);
for (int i = 0; i < n; i++) std::cin >> a[i];
for (int i = 0; i < n; i++) std::cin >> b[i];
for (int i = 0; i < n; i++) {
a[i] = std::max(a[i], b[i]);
min = std::min(min, a[i]);
}
// std::cout << Check(a, b, 18, n, m) << std::endl;
// return 0;
int l = 0, r = (int)1e18 + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (Check(a, b, mid, n, m)) {
l = mid;
} else {
r = mid;
}
}
std::cout << l;
}
# | 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... |