# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1015821 | ssitaram | Job Scheduling (CEOI12_jobs) | C++17 | 356 ms | 26072 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;
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n, d, m; cin >> n >> d >> m;
vector<pair<int, int>> jobs(m);
for (int i = 0; i < m; ++i) {
cin >> jobs[i].first;
--jobs[i].first;
jobs[i].second = i + 1;
}
sort(jobs.begin(), jobs.end());
auto plan = [&](int mach) -> pair<bool, vector<vector<int>>> {
vector<vector<int>> pl(n);
int idx = 0;
bool works = 1;
for (int i = 0; i < m; ++i) {
if (idx == n) {
works = 0;
break;
}
while (idx < jobs[i].first) {
++idx;
}
pl[idx].push_back(jobs[i].second);
if (idx > jobs[i].first + d) {
works = 0;
break;
}
if (pl[idx].size() == mach) {
++idx;
}
}
return make_pair(works, pl);
};
int lo = 1, hi = m;
while (lo < hi) {
int mi = (lo + hi) / 2;
if (plan(mi).first) {
hi = mi;
} else {
lo = mi + 1;
}
}
cout << lo << '\n';
vector<vector<int>> pl = plan(lo).second;
for (vector<int>& day : pl) {
for (int v : day) {
cout << v << ' ';
}
cout << "0\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |