# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
746269 | hasan_tawsif | Job Scheduling (CEOI12_jobs) | C++14 | 309 ms | 20576 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;
using LL = long long;
void solve() {
int n, d, m; cin >> n >> d >> m;
vector<pair<int, int > > v;
for (int i = 0; i < m; ++i) {
int x; cin >> x;
v.push_back({x, i + 1});
}
sort(v.begin(), v.end());
// for (auto [u, x] : v) cerr << u << " " << x << endl;
int lo = 1, hi = m;
vector<int> ans[n + 1];
auto test = [&] (int numOfMachine) {
int cur = 0, day = 1, tot = 0;
for (auto [u, x] : v) {
if (day == u or day - u <= d) {
tot++;
cur++;
} else return false;
cur %= numOfMachine;
if (cur == 0) day++;
}
return tot == m;
};
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (test(mid)) hi = mid;
else lo = mid + 1;
}
int cur = 0, day = 1, tot = 0;
for (auto [u, x] : v) {
if (day == u or day - u <= d) {
ans[day].push_back(x);
tot++;
cur++;
}
cur %= hi;
if (cur == 0) day++;
}
cout << hi << "\n";
for (int i = 1; i <= n; ++i) {
for (auto u : ans[i]) cout << u << " ";
cout << "0\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |