# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
925538 | 2024-02-11T23:43:06 Z | allw | Job Scheduling (CEOI12_jobs) | C++17 | 350 ms | 22600 KB |
#include <iostream> #include <vector> #include <algorithm> bool run(std::vector<std::pair<int, int>>& a, int d, int x, std::vector<std::vector<int>>& answer) { int i = 0; for (int j = 1; i < a.size() && j < answer.size(); ++j) { for (int k = 0; i < a.size() && k < x; ++k) { if (a[i].first > j) break; if (a[i].first + d < j) return false; if (j >= a[i].first && j <= a[i].first + d) { answer[j].push_back(a[i].second); ++i; } } } return i == a.size(); } int main() { int n, d, m; std::cin >> n >> d >> m; std::vector<std::pair<int, int>> a(m, {0, 0}); for (int i = 0; i < m; ++i) { std::cin >> a[i].first; a[i].second = i + 1; } std::sort(a.begin(), a.end()); int l = 0; int r = m; std::vector<std::vector<int>> answer; // (l, r] while (l + 1 < r) { answer = std::vector<std::vector<int>>(n + 1, std::vector<int>()); int middle = (l + r) / 2; if (run(a, d, middle, answer)) { r = middle; } else { l = middle; } } answer = std::vector<std::vector<int>>(n + 1, std::vector<int>()); run(a, d, r, answer); std::cout << r << '\n'; for (int i = 1; i <= n; ++i) { for (size_t j = 0; j < answer[i].size(); ++j) { std::cout << answer[i][j] << ' '; } std::cout << "0\n"; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 2464 KB | Output is correct |
2 | Correct | 29 ms | 2468 KB | Output is correct |
3 | Correct | 29 ms | 2724 KB | Output is correct |
4 | Correct | 29 ms | 2468 KB | Output is correct |
5 | Correct | 29 ms | 2476 KB | Output is correct |
6 | Correct | 29 ms | 2588 KB | Output is correct |
7 | Correct | 35 ms | 2724 KB | Output is correct |
8 | Correct | 29 ms | 2732 KB | Output is correct |
9 | Correct | 44 ms | 8556 KB | Output is correct |
10 | Correct | 43 ms | 9392 KB | Output is correct |
11 | Correct | 37 ms | 2308 KB | Output is correct |
12 | Correct | 75 ms | 4160 KB | Output is correct |
13 | Correct | 112 ms | 6632 KB | Output is correct |
14 | Correct | 184 ms | 9280 KB | Output is correct |
15 | Correct | 190 ms | 9668 KB | Output is correct |
16 | Correct | 262 ms | 12180 KB | Output is correct |
17 | Correct | 314 ms | 16616 KB | Output is correct |
18 | Correct | 309 ms | 16712 KB | Output is correct |
19 | Correct | 350 ms | 22600 KB | Output is correct |
20 | Correct | 312 ms | 16252 KB | Output is correct |