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 ll long long
ll n, m, a[310000], b[310000];
bool can (ll v) {
__int128_t now = 0;
for (int i = 1; i <= n; i++) {
ll inclass = (v + a[i] - 1) / a[i];
if (inclass == m) continue;
if (inclass < m) now += m - inclass;
else {
ll z = v - m * a[i];
now -= (z + b[i] - 1) / b[i];
}
}
return now >= 0;}
int main () {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
ll z = LLONG_MAX;
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]);
z= min(z, a[i]);
}
ll l = 0, r = 11e17;
while (l + 10 < r) {
ll mid = (l + r) / 2;
if (can(mid)) l = mid;
else r = mid;
}
while (can(l + 1)) l++;
// cout << can(19) << '\n';
cout << l << '\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... |