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 For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define Fors(i,a,b,s) for(int i=a;i<=b;i+=s)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define INF (ll)(9e18)
#define endl '\n'
#define int long long int
using namespace std;
using pii=pair<int,int>;
int UB=1000000000000000010;
int LB=0;
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N,M;
cin>>N>>M;
int tc=N*M;
int A[N],B[N];
for (int i=0;i<N;i++){
cin>>A[i];
}
for (int i=0;i<N;i++){
cin>>B[i];
}
while (LB!=UB){
int ndc=0;
int ddc=0;
int m=(LB+UB)/2;
for (int i=0;i<N;i++){
if (A[i]>B[i]){
int c=m/A[i]+1;
if (c<=M){
ddc+=M-c;
}
else{
ndc+=(m-A[i]*M)/B[i]+1;
}
}
else{
int c=m/B[i]+1;
if (c<=M){
ddc+=M-c;
}
else{
ndc+=(m-B[i]*M)/B[i]+1;
}
}
if (ndc>tc){
break;
}
}
if (ndc>ddc){
UB=m;
}
else{
LB=m+1;
}
}
cout<<UB<<endl;
}
# | 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... |