#include <bits/stdc++.h>
#define int long long
using namespace std;
const long long N = 3e5 + 5;
int a[N];
int b[N];
int n, m;
bool possible(int k)
{
int saved = 0;
for (int i = 0; i < n; i++)
{
int needed = (k + a[i] - 1) / a[i];
if (needed <= m)
{
saved += m - needed;
continue;
}
int left = k - m * a[i];
assert(left >= 0);
int others = (left + b[i] - 1) / b[i];
assert(others >= 0);
saved -= others;
}
return saved >= 0;
}
void solve()
{
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 = -1, r = 1e16 + 1;
while (r - l > 1)
{
int mid = (r + l) / 2;
possible(mid) ? (l = mid) : (r = mid);
}
cout << l;
// cout << possible(38404721679817) << endl;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++)
{
// cout << "Case #" << i << ':' << ' ';
solve();
cout << endl;
}
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... |