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 ll long long
#define ff first
#define ss second
using namespace std;
ll n,m;
ll a[300001],b[300001];
bool check(ll f){
ll raod=n*m;
vector<ll> v;
ll cnt=0;
for(ll k=1;k<=n;k++){
if(b[k]>=a[k]){
cnt=f/b[k];
if(f%b[k]!=0)
cnt++;
if(cnt>raod)
return 0;
raod-=cnt;
}
else{
v.push_back(k);
}
}
ll dar=0;
for(ll ind:v){
ll i=a[ind];
ll j=b[ind];
cnt=f/i;
if(f%i!=0)
cnt++;
if(cnt>m)
cnt=m;
if(raod<cnt)
return 0;
raod-=cnt;
dar=f-cnt*i;
if(dar<=0)
continue;
cnt=dar/j;
if(dar%j!=0)
cnt++;
if(raod<cnt)
return 0;
raod-=cnt;
}
if(raod<0)
return 0;
else
return 1;
}
int main(){
cin>>n>>m;
for(ll k=1;k<=n;k++){
cin>>a[k];
}
for(ll k=1;k<=n;k++){
cin>>b[k];
}
ll l=0,r=2*1e18;
ll md;
bool bl;
while(l<r){
md=(l+r+1)/2;
bl=check(md);
if(bl==1){
l=md;
}
else{
r=md-1;
}
}
cout<<l;
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... |