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;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
long long N, M; cin >> N >> M;
vector<int> A(N);
for(auto &i : A) cin >> i;
vector<int> B(N);
for(auto &i : B) cin >> i;
long long lo = 0;
long long hi = 1e18;
long long bst = 0;
while(lo <= hi){
long long mid = (lo + hi) / 2;
long long need = 0;
for(int i = 0; i < N && need <= N * M; i++){
long long needClass = (mid + max(A[i], B[i]) - 1) / max(A[i], B[i]);
if(needClass <= M){
need += needClass;
continue;
}
need += M;
long long left = mid - max(A[i], B[i]) * M;
need += (left + B[i] - 1) / B[i];
}
if(need <= N*M){
bst = mid;
lo = mid + 1;
}else hi = mid - 1;
}
cout << bst << "\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... |