#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |