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>
using namespace std;
long long a[300005], b[300005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, l=1, r=1e18;
cin >> n >> m;
for (long long i=1; i<=n; i++)
cin >> a[i];
for (long long i=1; i<=n; i++)
cin >> b[i];
while (l<r)
{
long long mid=(l+r+1)/2, cnt=0;
for (long long i=1; i<=n; i++)
{
if (a[i]<b[i])
cnt+=(mid-1)/b[i]+1;
else if (mid<=a[i]*m)
cnt+=(mid-1)/a[i]+1;
else
cnt+=m+(mid-a[i]*m-1)/b[i]+1;
}
if (cnt<=n*m)
l=mid;
else
r=mid-1;
}
cout << l;
}
# | 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... |