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;
bool works(long long mid, vector<long long>& a, vector<long long>& b, long long n, long long m){
long long days = 0;
for(long long i = 0; i < n; i++){
if(mid <= a[i] * m){
days += (mid + a[i] - 1) / a[i];
}
else{
days += m + (mid - a[i] * m + b[i] - 1) / b[i];
}
if(days > n * m){
return false;
}
}
return true;
}
int main(){
long long n, m;
cin >> n >> m;
vector<long long> a(n);
for(long long i = 0; i < n; i++){
cin >> a[i];
}
vector<long long> b(n);
for(long long i = 0; i < n; i++){
cin >> b[i];
}
for(long long i = 0; i < n; i++){
a[i] = max(a[i], b[i]);
}
long long low = 0;
long long high = 1LL << 60;
while(high - low > 1){
long long mid = (low + high)/2;
if(works(mid, a, b, n, m)){
low = mid;
}
else{
high = mid;
}
}
cout << low << "\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... |