#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];
}
int l = 0, r = 1e18, ans = - 1;
while(l <= r) {
int mid = (l + r) / 2;
int save = n * m;
for(int i = 1; i <= n; i++) {
int current = mid;
if(a[i] > b[i]) {
int cnt = min(m, (mid + a[i] - 1) / a[i]);
save -= cnt;
current -= cnt * a[i];
}
if(current > 0) {
save -= (current + b[i] - 1) / b[i];
}
}
if(save < 0) {
r = mid - 1;
}
else {
l = mid + 1;
ans = mid;
}
}
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... |