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;
const int N = 3e5 + 3;
int n, m, a[N], b[N];
bool check(long long d) {
long long sum = 0;
for (int i = 1; i <= n; ++i) {
long long x = d;
long long k = (x + a[i] - 1) / a[i];
k = min(k, (long long)m);
x -= k * a[i];
sum += k;
if (x > 0) sum += (x + b[i] - 1) / b[i];
if (sum > 1LL * n * m) return 0;
}
return 1;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
cin >> b[i], a[i] = max(a[i], b[i]);
long long l = 1, r = 1e18 + 7, ans = 0, mid;
while (l <= r) {
mid = (l + r) >> 1;
if (check(mid)) ans = mid, l = mid + 1;
else r = mid - 1;
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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... |