Submission #694201

#TimeUsernameProblemLanguageResultExecution timeMemory
694201vjudge1Job Scheduling (CEOI12_jobs)C++17
65 / 100
214 ms44536 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(s) s.begin(), s.end()
#ifndef LOCALDEBUG
#define LOCALDEBUG false
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int n, d, m;
vi requestsOnDay[(int)1e6 + 1];
int jobs[(int)1e6 + 1];

bool check(int machines)
{
    queue<int> active;
    for (int i = 1; i <= n; i++)
    {
        // get new requests
        for (int id : requestsOnDay[i])
            active.push(id);

        int mm = machines;
        while (!active.empty() && mm--)
        {
            int id = active.front();
            if (jobs[id] + d < i)
                return false;
            else
                active.pop();
        }
    }

    return active.empty();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> d >> m;
    for (int i = 0; i < m; i++)
    {
        int x;
        cin >> x;
        jobs[i] = x;
        requestsOnDay[x].pb(i);
    }

    int lo = 1, hi = m;
    while (lo < hi)
    {
        int mid = (lo + hi) / 2;
        if (check(mid))
            hi = mid;
        else
            lo = mid + 1;
    }

    cout << lo << '\n';

    vvi onDay(n + 1);

    queue<int> active;
    for (int i = 1; i <= n; i++)
    {
        // get new requests
        for (int id : requestsOnDay[i])
            active.push(id);

        int mm = lo;
        while (!active.empty() && mm--)
        {
            int id = active.front();
            onDay[i].pb(id);
            active.pop();
        }
    }

    for (int i = 1; i <= n; i++)
    {
        for (int id : onDay[i])
            cout << id + 1 << " ";
        cout << "0\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...