Submission #542543

#TimeUsernameProblemLanguageResultExecution timeMemory
542543TraingleJob Scheduling (CEOI12_jobs)C++14
100 / 100
403 ms29812 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 1; int n, d, m; vector<pair<int, int>> jobs; pair<bool, vector<vector<int>>> valid(int num) { vector<vector<int>> sched(n); int cnt = 0; for (int i = 1; i <= n; ++i) { for (int j = 0; j < num; ++j) { if (jobs[cnt].first > i) { break; } if (jobs[cnt].first + d >= i) { sched[i - 1].push_back(jobs[cnt++].second); } else { return {false, sched}; } if (cnt == m) { return {true, sched}; } } } return {false, sched}; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> d >> m; jobs.resize(m); for (int i = 0; i < m; ++i) { cin >> jobs[i].first; jobs[i].second = i + 1; } sort(jobs.begin(), jobs.end()); vector<vector<int>> sched; int lo = 1, hi = m; while (lo < hi) { int mid = lo + (hi - lo) / 2; pair<bool, vector<vector<int>>> cur = valid(mid); if (cur.first) { hi = mid; sched = cur.second; } else { lo = mid + 1; } } cout << lo << '\n'; for (int i = 0; i < n; ++i) { for (int j : sched[i]) { cout << j << ' '; } cout << "0\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...