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 INF = 1e18;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, w;
cin >> n >> w;
vector<int> a(n), b(n);
for (auto& el : a)
cin >> el;
for (auto& el : b)
cin >> el;
for (int i = 0; i < n; ++i)
a[i] = max(a[i], b[i]);
int l = 0, r = INF;
while (l + 1 < r) {
int m = (l + r) / 2;
int extra = 0, need = 0;
for (int i = 0; i < n; ++i) {
if (a[i] * w >= m) {
extra += w - ((m + a[i] - 1) / a[i]);
continue;
}
need += (m - a[i] * w + b[i] - 1) / b[i];
}
if (extra >= need)
l = m;
else
r = m;
}
cout << l << '\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... |