Submission #1243774

#TimeUsernameProblemLanguageResultExecution timeMemory
1243774inkvizytorJob Scheduling (CEOI12_jobs)C++20
100 / 100
112 ms14276 KiB
#include <bits/stdc++.h>
using namespace std;

bool czy (int n, int d, vector<int> &v, vector<int> &sp, int k) {
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < v[i]; j++) {
            q.push(i);
        }
        if ((!q.empty()) && (q.front()+d<i)) {
            return 0;
        }
        for (int j = 0; j < k; j++) {
            if (q.empty()) {
                break;
            }
            q.pop();
        }
    }
    return 1;
}



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, d, m;
    cin >> n >> d >> m;
    vector<int> v (n+1, 0), sp (n+1, 0);
    vector<vector<int>> c (n+1);
    for (int i = 1; i < m+1; i++) {
        int x;
        cin >> x;
        v[x]++;
        c[x].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
        sp[i] = sp[i-1]+v[i];
    }
    int k = 0;
    int p = 1<<29;
    while (p > 0) {
        k += p;
        if (czy(n, d, v, sp, k)) {
            k -= p;
        }
        p /= 2;
    }
    k++;
    cout << k << '\n';
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        for (int j : c[i]) {
            q.push(j);
        }
        for (int j = 0; j < k; j++) {
            if (q.empty()) {
                break;
            }
            cout << q.front() << ' ';
            q.pop();
        }
        cout << "0\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...