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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
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];
}
auto check = [&](long long K) -> bool {
long long cnt = 0;
for (int i = 0; i < N; ++i) {
auto X = K;
if (A[i] > B[i]) {
int dec = min((long long) M, (X - 1) / A[i] + 1);
X -= (long long) dec * A[i];
cnt += dec;
}
if (X > 0) {
cnt += (X - 1) / B[i] + 1;
}
if (cnt > (long long) N * M) {
return 0;
}
}
return 1;
};
long long L = 1, R = 1e18, res = 0;
while (L <= R) {
auto md = (L + R) / 2;
if (check(md)) {
res = md;
L = md + 1;
} else {
R = md - 1;
}
}
cout << res;
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... |