#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
int n, k;
int a[300010];
int b[300010];
bool check(int m, int s = 0) {
for (int i = 1; i <= n; i++) {
if (a[i] * k >= m) s += (m + a[i] - 1) / a[i];
else s += k + (m - a[i] * k + b[i] - 1) / b[i];
if (s > n * k) return 0;
}
return 1;
}
int search(int l, int r) {
while (l < r) {
int m = (l + r + 1) / 2;
if (check(m)) l = m;
else r = m - 1;
}
return l;
}
void solve () {
cin >> n >> k;
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]);
cout << search(0, 2e18) << '\n';
}
signed main() {IOS solve(); 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... |