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;
mt19937 rnd(51);
#define ll long long
#define pb push_back
#define ld long double
const ll INF = 1e18 + 100;
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
ll l = 0, r = INF;
while (r - l > 1) {
ll mid = (r + l) / 2, need = 0, free = 0;
for (int i = 0; i < n; i++) {
if (a[i] > b[i]) {
if ((ll)a[i] * m < mid) {
need += (mid - (ll)a[i] * m + b[i] - 1) / b[i];
need = min(need, INF);
} else {
free += m - (mid + a[i] - 1) / a[i];
}
} else {
need += (mid + b[i] - 1) / b[i];
need = min(need, INF);
free += m;
}
}
if (need <= free) {
l = mid;
} else {
r = mid;
}
}
cout << l << endl;
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... |