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 MAX 305000
using ll = long long;
ll A[MAX],B[MAX];
ll N,M;
ll teto(ll a,ll b){
ll c = a/b;
if(a%b)++c;
return c;
}
bool possivel(ll x){
ll sum=0;
for(int i=0;i!=N;++i){
ll necessario = teto(x,A[i]);
ll gastar = std::min(necessario,M);
ll falta = x-(gastar*A[i]);
if(falta>0){
ll precisa = teto(falta,B[i]);
sum-=precisa;
}else {
ll sobra = M-gastar;
sum+=sobra;
}
}
return sum>=0;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin>>N>>M;
for(int i=0;i!=N;++i)std::cin>>A[i];
for(int i=0;i!=N;++i)std::cin>>B[i];
for(int i=0;i!=N;++i){
if(A[i]<B[i]){
A[i]=B[i];
}
}
ll l=1,r=1LL<<60LL;
while(l<r){
ll m=(l+r+1)/2;
if(possivel(m)){
l=m;
}else r=m-1;
}
std::cout<<l<<"\n";
}
# | 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... |