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;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
const ll inf = 3e18;
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];
}
ll L = 0, R = inf;
while (L + 1 < R) {
ll mid = (L + R) >> 1;
auto check = [&]() -> bool {
ll cnt = n * (ll)m;
for (int i = 0; i < n; ++i) {
if (b[i] >= a[i]) {
ll now = (mid + b[i] - 1) / b[i];
cnt -= now;
} else {
ll now = (mid + a[i] - 1) / a[i];
if (now <= m) {
cnt -= now;
} else {
ll whole = m + (mid - a[i] * m + b[i] - 1) / b[i];
cnt -= whole;
}
}
}
return cnt >= 0;
};
if (check()) {
L = mid;
} else {
R = mid;
}
}
cout << L;
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... |