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 int long long
using namespace std;
const int nmax = 3e5 + 1;
int a[nmax], b[nmax], n, m;
bool check(int x) {
int day = 0;
for(int i = 1; i <= n; i++){
if(x <= a[i] * m) day += (x + a[i] - 1) / a[i];
else day += m + (x - a[i] * m + b[i] - 1) / b[i];
if(day > n * m) return 0;
}
return 1;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
}
for(int i = 1; i <= n; i ++) {
cin >> b[i];
a[i] = max(a[i], b[i]);
}
int l = 0, r = 1e18, ans = 0;
while(l <= r) {
int mid = (l + r) / 2;
if(check(mid) == true) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << ans;
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... |