제출 #1165520

#제출 시각아이디문제언어결과실행 시간메모리
1165520thinknoexitJob Scheduling (CEOI12_jobs)C++20
100 / 100
108 ms13608 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> bucket[100100];
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, d, m;
    cin >> n >> d >> m;
    for (int i = 1;i <= m;i++) {
        int x;
        cin >> x;
        bucket[x].push_back(i);
    }
    int l = 1, r = m;
    while (l < r) {
        int mid = (l + r) / 2;
        bool ch = 1;
        queue<int> q;
        for (int i = 1;i <= n;i++) {
            if (!q.empty() && q.front() + d < i) {
                ch = 0;
                break;
            }
            for (int j = 0;j < (int)bucket[i].size();j++)
                q.push(i);
            for (int j = 1;j <= mid && !q.empty();j++) q.pop();
        }
        if (ch && q.empty()) r = mid;
        else l = mid + 1;
    }
    cout << l << '\n';
    queue<int> q;
    for (int i = 1;i <= n;i++) {
        for (auto& x : bucket[i]) q.push(x);
        for (int j = 1;j <= l && !q.empty();j++) {
            cout << q.front() << ' ';
            q.pop();
        }
        cout << "0\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...