Submission #924695

#TimeUsernameProblemLanguageResultExecution timeMemory
924695tz74Job Scheduling (CEOI12_jobs)C++17
60 / 100
1071 ms65536 KiB
#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 timeMemoryGrader output
Fetching results...