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
const int MAX_N = 3*1e5;
int n, m, A[MAX_N], B[MAX_N], C[MAX_N];
bool check(int target){
//cout<<"target "<<target<<endl;
for(int i = 0; i<n; i++){
C[i] = A[i] * m;
}
int excess= 0;
for(int i = 0; i<n; i++){
if(C[i]>target){
excess += (C[i]-target)/A[i];
C[i]-= ((C[i]-target)/A[i])*A[i];
}
}
for(int i = 0; i<n; i++){
if(C[i]<target){
int need = (target-C[i]+B[i]-1)/B[i];
if(excess>=need){
excess-=need;
}
else{
return false;
}
}
}
return true;
}
signed main(){
cin>>n>>m;
for(int i = 0; i<n; i++){
cin>>A[i];
}
for(int i = 0; i<n; i++){
cin>>B[i];
A[i] = max(A[i], B[i]);
}
int res= 0LL;
for(int step = (1LL<<61LL); step>=1LL; step/=2LL){
//cout<<"hello "<<step<<endl;
if(check(res+step)){
res+=step;
}
}
cout<<res<<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... |