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
const int MAXN = 3e5 + 10;
int a[MAXN], b[MAXN];
int n, m;
bool check(int x) {
int rem = 0;
vector<int> need(n);
for (int i = 0; i < n; i++) {
int qtd = ((x + a[i] - 1)/a[i]);
if (qtd > m) need[i] = (x - m*a[i]);
else rem += (m - qtd);
}
for (int i = 0; i < n; i++) {
int qtd = ((need[i] + b[i] - 1)/b[i]);
rem -= qtd;
if (rem < 0) return 0;
}
return 1;
}
int32_t main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
a[i] = max(a[i], b[i]);
}
int l = 0, r = 1e18, ans;
while (l <= r) {
int m = (l+r)/2;
if (check(m)) {
ans = m;
l = m + 1;
} else {
r = m - 1;
}
}
cout << ans << "\n";
}
# | 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... |