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;
#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,a[300005],b[300005],i,ans,l,r,w,m,sum;
cin>>n>>m;
for (i=1;i<n+1;i++) cin>>a[i];
for (i=1;i<n+1;i++) cin>>b[i];
ans=0;l=0;r=1e18;
while (l<=r)
{
w=(l+r)/2;
bool tr=true;
sum=0;
for (i=1;i<n+1;i++)
{
if (a[i]>b[i])
{
if (a[i]*m>=w) sum += w/a[i] + (w%a[i]!=0);
else sum += m + (w-a[i]*m)/b[i] + ((w-a[i]*m)%b[i]!=0);
}
else sum += w/b[i] + (w%b[i]!=0);
if (sum>n*m) tr=false;
}
if (tr)
{
ans=w;l=w+1;
}
else r=w-1;
}
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... |