제출 #543109

#제출 시각아이디문제언어결과실행 시간메모리
543109Saeed_247Job Scheduling (CEOI12_jobs)C++14
100 / 100
222 ms16896 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int n, m, d, arr[N];
vector<int> adj[N];

bool check(int x) {
    queue<int> st;
    int delay = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < arr[i]; j++) st.push(i);
        int t = st.size();
        for (int j = 0; j < min(x, t); j++) {
            delay = max(delay, abs(i - st.front()));
            st.pop();
        }
    }
    if (!st.empty()) {
        return false;
    }
    return delay <= d;
}

void print(int x) {
    queue<int> st;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < arr[i]; j++) st.push(adj[i][j]);
        int t = st.size();
        for (int j = 0; j < min(x, t); j++) {
            cout << st.front() << ' ';
            st.pop();
        }
        cout << "0\n";
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> d >> m;
    for (int i = 0; i < m; i++) {
        int in; cin >> in;
        arr[in]++;
        adj[in].push_back(i + 1);
    }
    int lo = 1, hi = m;
    while (lo < hi) {
        int mid = (lo + hi) / 2;
        if (check(mid)) {
            hi = mid;
        }
        else {
            lo = mid + 1;
        }
    }
    cout << hi << '\n';
    print(hi);
    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...