Submission #1221353

#TimeUsernameProblemLanguageResultExecution timeMemory
1221353plasmatic8Job Scheduling (CEOI12_jobs)C++20
55 / 100
320 ms24868 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int n, d, m; vector<pair<int, int>> b; // Function to check if it's possible to complete all jobs with `machines` machines per day bool solve(int machines) { vector<int> did; int day = 0; for (int i = 0; i < m; i += machines) { day++; int end = min(m, i + machines); for (int j = i; j < end; ++j) { did.push_back(max(b[j].first, day) - b[j].first); } } for (int delay : did) { if (delay > d) return false; } return true; } // Binary search for the smallest number of machines that work int first_true(int lo, int hi) { hi++; while (lo < hi) { int mid = (lo + hi) / 2; if (solve(mid)) hi = mid; else lo = mid + 1; } return lo; } int main() { cin >> n >> d >> m; vector<int> a(m); for (int i = 0; i < m; ++i) { cin >> a[i]; b.push_back({a[i], i + 1}); } sort(b.begin(), b.end()); int machines = first_true(1, n); cout << machines << endl; vector<int> did; int day = 0, wrote = 0; for (int i = 0; i < m; i += machines) { day++; vector<int> ans; int end = min(m, i + machines); for (int j = i; j < end; ++j) { did.push_back(max(b[j].first, day) - b[j].first); ans.push_back(b[j].second); } for (int x : ans) cout << x << " "; cout << "0\n"; wrote++; } for (int i = 0; i < n - wrote; ++i) cout << "0\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...