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
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
for (int i = 1; i <= n; ++i) a[i] = max(a[i], b[i]);
__int128 l = 1, r = 1e18 * 1e9, sol = 0;
while (l <= r) {
__int128 mid = (l + r) / 2;
__int128 days = 0;
__int128 need = 0;
for (int i = 1; i <= n; ++i) {
if ((__int128) a[i] * m >= mid) {
days += (__int128) m - (mid + a[i] - 1) / a[i];
} else {
need += (__int128) (mid - (__int128) a[i] * m + b[i] - 1) / (__int128) b[i];
}
}
if (need <= days) {
sol = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
if (sol == 0) {
cout << 0;
return 0;
}
vector<int> d;
while (sol > 0) {
d.push_back(sol % 10);
sol /= 10;
}
reverse(d.begin(), d.end());
for (auto i : d) cout << i;
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... |