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);
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 bot, top, mid;
bot = 0;
top = 1e18;
while (bot <= top) {
mid = (bot + top) / 2;
long long remain = 0;
for (int i = 0; i < n; i++) {
long long need;
if (b[i] >= a[i]) {
remain += m;
need = (mid - 1) / b[i] + 1;
remain -= need;
}
else {
need = (mid - 1) / a[i] + 1;
if (need <= m) {
remain += (m - need);
}
else {
need = (mid - m * a[i] - 1) / b[i] + 1;
remain -= need;
}
}
}
if (remain >= 0) bot = mid + 1;
else top = mid - 1;
}
cout << top << "\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... |