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 <vector>
#include <iostream>
using namespace std;
long long n, m;
vector<int> course;
vector<int> study;
bool works(long long target) {
vector<long long> vals(n); // value of each class rn
long long hours = n * m;
long long temp;
long long left = 0;
for (int i = 0; i < n; i++) {
if (course[i] > study[i]) {
temp = target / course[i];
if (target % course[i] != 0) {
temp++;
}
temp = min(temp, m);
hours -= temp;
vals[i] += course[i] * temp;
}
if (vals[i] < target) {
left = target - vals[i];
temp = left / study[i];
if (left % study[i] != 0) {
temp++;
}
hours -= temp;
vals[i] += temp * study[i];
}
if (hours < 0) {
return false;
}
// cout << hours << ' ';
}
return true;
}
int main() {
cin >> n >> m;
course.resize(n);
study.resize(n);
for (int i = 0; i < n; i++) {
cin >> course[i];
}
for (int i = 0; i < n; i++) {
cin >> study[i];
}
// binary search for max min comprehension lvl
long long low = 0;
long long high = 1e18;
long long mid;
long long working = 0;
while (low <= high) {
mid = (low + high) / 2;
if (works(mid)) {
working = mid;
low = mid + 1;
}
else {
high = mid - 1;
}
}
cout << working;
}
# | 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... |