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;
void solve() {
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];
}
long long l = 0, r = 1000000000 * 1LL * 1000000000 + 7;
while (l < r - 1) {
long long md = (l + r) / 2;
long long free = 0;
for (int i = 0; i < n; ++i) {
if (a[i] <= b[i]) {
free += m;
free -= (md - 1) / b[i] + 1;
} else if (a[i] * 1LL * m >= md) {
long long vl = (md - 1) / a[i] + 1;
free += m - vl;
} else {
free -= (md - a[i] * 1LL * m - 1) / b[i] + 1;
}
if (free < -n * 1LL * m) {
break;
}
}
if (free >= 0) {
l = md;
} else {
r = md;
}
}
cout << l << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
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... |