# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085368 | juicy | Job Scheduling (CEOI12_jobs) | C++17 | 1047 ms | 18256 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 <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, d, m; cin >> n >> d >> m;
vector<int> a(m);
for (int i = 0; i < m; ++i) {
cin >> a[i]; -- a[i];
}
vector<int> ord(m); iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return a[i] < a[j];
});
vector<vector<int>> events(n);
auto check = [&](int md) -> bool {
priority_queue<array<int, 2>, vector<array<int, 2>>, greater<array<int, 2>>> pq;
for (int i = 0, j = 0; i < n; ++i) {
if (pq.size() && pq.top()[0] < i) {
return 0;
}
while (j < m && a[ord[j]] == i) {
pq.push({i + d, ord[j++]});
}
int cnt = md;
while (cnt-- && pq.size()) {
pq.pop();
}
}
return !pq.size();
};
auto qry = [&](int md) {
priority_queue<array<int, 2>, vector<array<int, 2>>, greater<array<int, 2>>> pq;
for (int i = 0, j = 0; i < n; ++i) {
while (j < m && a[ord[j]] == i) {
pq.push({i + d, ord[j++]});
}
int cnt = md;
while (cnt-- && pq.size()) {
events[i].push_back(pq.top()[1]);
pq.pop();
}
}
};
int l = 0, r = m, res = m;
while (l <= r) {
int md = (l + r) / 2;
if (check(md)) {
res = md;
r = md - 1;
} else {
l = md + 1;
}
}
qry(res);
cout << res << "\n";
for (int i = 0; i < n; ++i) {
for (int j : events[i]) {
cout << j + 1 << " ";
}
cout << 0 << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |