# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924695 | tz74 | Job Scheduling (CEOI12_jobs) | C++17 | 1071 ms | 65536 KiB |
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 <iostream>
#include <vector>
#include <set>
using namespace std;
int N, D, M;
multiset<pair<int, int> > rq_base;
bool check(int n_machines, bool show) {
int available = n_machines;
multiset<int> current;
set<pair<int, int> > pending;
multiset<pair<int, int> > rq= rq_base;
for (int day = 1; day <= N; day++) {
auto c_it = current.begin();
while (c_it != current.end()) {
if (*c_it <= day) {
available++;
c_it = current.erase(c_it);
} else {
break;
}
}
auto p_it = rq.begin();
while (p_it != rq.end()) {
if (p_it->first <= day) {
// must finish before day + D
pending.insert(make_pair(p_it->first + D, p_it->second));
p_it = rq.erase(p_it);
} else {
break;
}
}
// pop the ones that have tightest requirements
while (available != 0 && !pending.empty()) {
int need = pending.begin()->first;
if (need < day) {
return false;
}
if (show) printf("%d ", pending.begin()->second);
// will get this printer back the next day
current.insert(day + 1);
pending.erase(pending.begin());
available--;
}
if (show) printf("0\n");
}
return true;
}
int main(void) {
cin >> N >> D >> M;
for (int i = 1; i <= M; i++) {
int d; cin >> d;
rq_base.insert(make_pair(d, i));
}
int lo = 1, hi = 1e6;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (check(mid, 0)) {
hi = mid;
} else {
lo = mid + 1;
}
}
printf("%d\n", lo);
check(lo, 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |