#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> a(n + 1, 0);
vector<int> b(n + 1, 0);
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]);
}
int l = 0, r = 1e18, ans = - 1;
while(l <= r) {
int mid = (l + r) / 2;
int save = 0;
int ok = 1;
for(int i = 1; i <= n; i++) {
if(m * a[i] >= mid) {
save += m - (mid + a[i] - 1) / a[i];
}
}
for(int i = 1; i <= n; i++) {
if(m * a[i] < mid) {
save -= (mid - m * a[i] + b[i] - 1) / b[i];
}
if(save < 0) {
ok = 0;
}
}
if(ok) {
l = mid + 1;
ans = mid;
}
else {
r = mid - 1;
}
}
cout << ans;
}
# | 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... |