Submission #1351050

#TimeUsernameProblemLanguageResultExecution timeMemory
1351050kantaponzJob Scheduling (CEOI12_jobs)C++20
100 / 100
135 ms23036 KiB
#include <bits/stdc++.h>
using namespace std;

const int nx = 1e5 + 5;

vector<int> add[nx], qrs[nx];
int n, d, m;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n >> d >> m;
    for (int i = 1; i <= m; i++) {
        int x; cin >> x;
        add[x].emplace_back(i);
        qrs[x + d + 1].emplace_back(i);
    }
    // search from 1 -> n + 1

    int l = 1, r = m;
    while (l < r) {
        int mid = (l + r) / 2;
        queue<int> q;
        bool del[10*nx];
        memset(del, 0, sizeof del);
        bool ok = 1;
        for (int i = 1; i <= n + 1; i++) {
            for (auto idx : qrs[i]) {
                if (!del[idx]) {
                    ok = 0;
                    //cout << mid << " " << idx << "\n";
                    break;
                }
            }
            if (!ok) break;
            for (auto idx : add[i]) q.emplace(idx);
            int ct = 0;
            //cout << i << " : ";
            while (!q.empty() && ct < mid) {
                ct++;
                del[q.front()] = 1;
                //cout << q.front() << " ";
                q.pop();
            }
            //cout << endl;
        }
        if (ok) r = mid;
        else l = mid + 1;
    }

    vector<int> ans[n + 1];
    cout << l << "\n";
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        for (auto idx : add[i]) q.emplace(idx);
        int ct = 0;
        while (!q.empty() && ct < l) {
            ct++;
            ans[i].push_back(q.front());
            q.pop();
        }
        for (auto idx : ans[i]) {
            cout << idx << " ";
        }
        cout << 0 << "\n";
    }
    
}

/*

8 2 12 
1 2 4 2 1 3 5 6 2 3 6 4

2
5 1 0
9 4 0
2 10 0
6 12 0
3 7 0
11 8 0
0
0

*/
#Verdict Execution timeMemoryGrader output
Fetching results...