# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104808 | WLZ | Job Scheduling (CEOI12_jobs) | C++17 | 5 ms | 384 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 n, d, m;
vector<int> a;
vector< vector<int> > v;
int check(int k) {
vector<int> cnt(n + 1, 0);
int last = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == 0) {
continue;
}
int left = a[i];
int pos = d + 1;
if (last >= i) {
left -= k - cnt[last];
pos = i + d - last;
}
if ((left + k - 1) / k > pos) {
return 0;
}
last = max(i, last) + (left + k - 1) / k;
cnt[last] = left % k;
}
return 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
freopen("in.txt", "r", stdin);
cin >> n >> d >> m;
a.assign(n + 1, 0);
v.resize(n + 1);
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
a[x]++;
v[x].push_back(i);
}
int lo = 1, hi = m, ans;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (check(mid)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
vector< vector<int> > ansv(2 * n + 1);
for (int i = 1; i <= n; i++) {
int pos = i;
while (!v[i].empty()) {
while ((int) ansv[pos].size() < ans && !v[i].empty()) {
ansv[pos].push_back(v[i].back());
v[i].pop_back();
}
pos++;
}
}
cout << ans << '\n';
for (int i = 1; i <= n; i++) {
for (auto& x : ansv[i]) {
cout << x << ' ';
}
cout << 0 << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |