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"
#include <functional>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<ll> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
a[i] = max(a[i], b[i]);
}
auto check = [&](ll mid) -> bool {
ll freeLesson = 0;
for (int i = 0; i < n; i++) {
ll numLesson = mid / a[i] + ((mid % a[i] == 0) ? 0 : 1);
// cout << "@@@" << i << " " << a[i] << " " << numLesson << endl;
if (numLesson < m) {
freeLesson += m - numLesson;
}
}
// cout << mid << " " << freeLesson << endl;
for (int i = 0; i < n; i++) {
ll numLesson = mid / a[i] + ((mid % a[i] == 0) ? 0 : 1);
if (numLesson > m) {
ll stillNeed = max(0ll, mid - m * a[i]);
freeLesson -= stillNeed / b[i] + ((stillNeed % b[i] == 0) ? 0 : 1);
}
if (freeLesson < 0) return false;
}
return true;
};
ll l = 0;
ll r = 1e18;
while (l <= r) {
ll mid = (l + r) / 2;
if (check(mid)) {
l = mid + 1;
}
else {
r = mid - 1;
}
}
cout << r << "\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... |