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 <iostream>
using namespace std;
const long long INF = 5e18;
int main(){
cin.tie(0)->sync_with_stdio(0);
long long n, m; cin >> n >> m;
long long a[n], b[n];
for (int i = 0; i < n; i++){
cin >> a[i];
}
for (int i = 0; i < n; i++){
cin >> b[i];
}
auto check = [&](long long x) -> bool {
long long cnt = 0;
for (int i = 0; i < n; i++){
if (a[i] > b[i]){
if (a[i] * m >= x){
cnt += x / a[i] + (bool)(x % a[i]);
}else{
cnt += m;
long long y = x - m * a[i];
cnt += y / b[i] + (bool)(y % b[i]);
}
}else{
cnt += x / b[i] + (bool)(x % b[i]);
}
}
return cnt <= n * m;
};
long long l = 0, r = INF;
while (l < r - 1){
long long mid = (l + r) / 2;
if (check(mid)){
l = mid;
}else{
r = mid;
}
}
cout << l;
return 0;
}
# | 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... |