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<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
const ll maxn=300010;
ll n,m;
ll a[maxn],b[maxn];
bool chk(ll x)
{
ll ret=0;
for(ll i=1;i<=n;i++)
{
if(a[i]<=b[i])
ret+=(x+b[i]-1)/b[i];
else
{
ll kappa=(x+a[i]-1)/a[i];
kappa=min(kappa,m);
ret+=kappa;
ll h=kappa*a[i];
if(x>h)
ret+=((x-h)+b[i]-1)/b[i];
if(ret>n*m)
return 0;
}
}
return 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
for(ll i=1;i<=n;i++)
cin>>a[i];
for(ll i=1;i<=n;i++)
cin>>b[i];
ll lo=0,hi=1e18;
while(lo<hi)
{
ll m=(lo+hi)/2;
if(chk(m))
lo=m+1;
else
hi=m-1;
}
cout<<lo;
}
# | 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... |