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;
#define int long long
#define f first
#define s second
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0;i < n;i++)
cin >> a[i];
vector<int> b(n);
for (int i = 0;i < n;i++)
cin >> b[i];
int l = 0, r = 1e18, ans = 0;
auto check = [&](int mid) {
int uk = n * m;
for (int i = 0;i < n;i++) {
int d = 0, t = mid;
if (a[i] > b[i]) {
int x = min(m, (t + a[i] - 1) / a[i]);
t -= x * a[i];
d += x;
}
if (t > 0)
d += (t + b[i] - 1) / b[i];
if (d > uk)
return false;
uk -= d;
}
return true;
};
while (l <= r) {
int mid = l + (r - l) / 2;
if (check(mid)) {
ans = mid;
l = mid + 1;
}
else
r = mid - 1;
}
cout << ans << '\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... |