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 <iostream>
#include <algorithm>
#define f first
#define s second
using namespace std;
long long n, m, a[300010], b[300010], ans;
__int128 l = 0, r = 1e20, mid, cnt, req;
bool check() {
cnt = req = 0;
for (int i = 1; i <= n; i++) {
if (b[i] > a[i]) {
cnt += m;
req += (mid+b[i]-1)/b[i];
} else {
if (a[i]*m >= mid) cnt += (a[i]*m-mid)/a[i];
else req += (mid-a[i]*m+b[i]-1)/b[i];
}
}
if (cnt < req) return 0;
else return 1;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
while (l <= r) {
mid = (l+r)/2;
if (!check()) r = mid-1;
else l = mid+1;
}
ans = r;
cout << ans << endl;
}
# | 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... |