제출 #106641

#제출 시각아이디문제언어결과실행 시간메모리
106641naoaiJob Scheduling (CEOI12_jobs)C++14
100 / 100
487 ms20700 KiB
#include <bits/stdc++.h>

using namespace std;

#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");

const int mmax = 1e6 + 5;

int n, d, m;
int a[mmax + 1];
pair<int, int> v[mmax + 1];

bool check (int val) {
    int i = 1;
    for (int z = 1; z <= n; ++ z) {
        int aux = i;
        for (int j = i; j < i + val && a[j] <= z && j <= m; ++ j, ++ aux) {
            if (a[j] + d < z)
                return 0;
        }
        i = aux;
    }

    return 1;
}

int main() {
   // ios::sync_with_stdio(0); cin.tie(nullptr);
    cin >> n >> d >> m;

    for (int i = 1; i <= m; ++ i) {
        int x;
        cin >> x;
        a[i] = x;
        v[i] = {x, i};
    }

    int n2 = 1;
    for (n2 = 1; (n2 << 1) <= m; n2 <<= 1) {
    }

    sort(a + 1, a + m + 1);

    int ans = m;
    for (int step = n2; step > 0; step >>= 1) {
        if (ans - step > 0 && check(ans - step)) {
            ans -= step;
        }
    }

    sort(v + 1, v + m + 1);

    cout << ans << "\n";

    int i = 1;
    for (int z = 1; z <= n; ++ z) {
        int aux = i;
        for (int j = i; j < i + ans && a[j] <= z && j <= m; ++ j, ++ aux) {
            cout << v[j].second << " ";
        }

        i = aux;
        cout << "0\n";
    }

    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...