Submission #928062

#TimeUsernameProblemLanguageResultExecution timeMemory
928062megaminionJob Scheduling (CEOI12_jobs)C++17
100 / 100
175 ms27248 KiB
#include <bits/stdc++.h>
#define pb push_back
#define ins insert
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define endl '\n'
using namespace std;
const int M = 1e6;
const int N = 1e5;

int n, d, m;
int a[M], mp[N+1];
vector<int> v[N+1];
vector<int> p[N+1];

bool ok(int x, bool flag)
{
    bool ret = true;
    deque<int> dq;
    for(int i = 1; i <= n; ++i)
    {
        if(flag)
            v[i].clear();
        for(int j = 0; j < mp[i]; ++j)
        {
            dq.pb(i);
        }
        for(int j = 0; j < x; ++j)
        {
            if(dq.empty()) break;
            ret &= i - dq[0] <= d;
            if(flag)
            {
                v[i].pb(p[dq[0]].back());
                p[dq[0]].pop_back();
            }
            dq.pop_front();
        }
    }
    return ret;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>d>>m;
    for(int i = 0; i < m; ++i)
    {
        cin>>a[i];
        mp[a[i]]++;
        p[a[i]].pb(i+1);
    }
    int L = 1, R = 1e6, mid;
    while(L < R)
    {
        mid = L + (R - L) / 2;
        if(ok(mid, false))
        {
            R = mid;
        }
        else
        {
            L = mid+1;
        }
    }
    assert(ok(L, true));
    cout<<L<<endl;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j < sz(v[i]); ++j)
        {
            cout<<v[i][j];
            if(j + 1 != sz(v[i])) cout<<" ";
            else cout<<" 0";
        }
        if(v[i].empty())
        {
            cout<<"0";
        }
        if(i != n) cout<<endl;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...