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>
#define int long long
using namespace std;
void solve()
{
int n, m;
cin >> n >> m;
vector<int> a(n), b(n);
for (int &i : a)
cin >> i;
for (int &i : b)
cin >> i;
int l = 0, r = 3e18;
while (l + 1 < r)
{
int mid = (l + r) >> 1, lft = n * m;
for (int i = 0; i < n && lft >= 0; ++i)
if (a[i] <= b[i])
{
int cnt = mid / b[i] + (mid % b[i] > 0);
assert(cnt * b[i] >= mid && (cnt - 1) * b[i] < mid);
lft -= cnt;
}
else
{
int cnt = mid / a[i] + (mid % a[i] > 0);
cnt = min(cnt, m);
lft -= cnt;
if (lft < 0)
break;
if (cnt * a[i] < mid)
{
cnt = (mid - cnt * a[i]) / b[i] + ((mid - cnt * a[i]) % b[i] > 0);
lft -= cnt;
}
}
if (lft >= 0)
l = mid;
else
r = mid;
}
cout << l << '\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
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... |