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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> 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 check = [&](__int128_t k) {
vector<__int128_t> left(n, k);
__int128_t weeks_left = (__int128_t) n * m;
for (int i = 0; i < n; i++) {
__int128_t div = min((__int128_t) m, (k + a[i] - 1) / a[i]);
left[i] = max((__int128_t) 0, left[i] - a[i] * div);
weeks_left -= div;
}
for (int i = 0; i < n; i++) weeks_left -= (left[i] + b[i] - 1) / b[i];
return weeks_left >= 0;
};
__int128_t lo = 0, hi = (__int128_t) 2e18;
while (lo < hi) {
__int128_t mid = (lo + hi + 1) / 2;
if (check(mid)) lo = mid;
else hi = mid - 1;
}
cout << (long long) lo << '\n';
return 0;
}
# | 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... |