Submission #1295874

#TimeUsernameProblemLanguageResultExecution timeMemory
1295874trandaihao5555Job Scheduling (CEOI12_jobs)C++20
100 / 100
249 ms29040 KiB
#include <bits/stdc++.h>

#define int long long

#define debug     cout << "ok\n";
#define SQR(x)    (1LL * ((x) * (x)))
#define MASK(i)   (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define fi        first
#define se        second
#define pb        push_back

#define mp make_pair
#define pii pair<int,int>
#define pli pair<ll,int>
#define vi vector<int>

#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui;

using namespace std;

const int M = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFLL = (ll)2e18 + 7LL;
const ld PI = acos(-1);

const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};

template<class _, class __>
    bool minimize(_ &x, const __ y){
        if(x > y){
            x = y;
            return true;
        } else return false;
    }
template<class _, class __>
    bool maximize(_ &x, const __ y){
        if(x < y){
            x = y;
            return true;
        } else return false;
    }

template<class _,class __>
    void Add(_ &x, const __ y) {
        x += y;
        if (x >= M) {
            x -= M;
        }
        return;
    }

template<class _,class __>
    void Diff(_ &x, const __ y) {
        x -= y;
        if (x < 0) {
            x += M;
        }
        return;
    }

//--------------------------------------------------------------

const int MaxN = 1e6+7;

int m,d,n,res;
pii a[MaxN];
vi lis[MaxN];

bool check(int ans) {
    for (int i=1;i<=m;i++) lis[i].clear();
    queue<int> q;
    for (int i=1,j=1;i<=m;i++) {
        while (j <= n && a[j].fi <= i) {
            q.push(j);
            j++;
        }
        if (!q.empty() && a[q.front()].fi + d < i) return false;
        for (int k=1;k<=ans && !q.empty();k++) {
            lis[i].pb(a[q.front()].se);
            q.pop();
        }
    }
    return q.empty();
}

void sol() {
    cin >> m >> d >> n;
    for (int i=1;i<=n;i++) {
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort(a+1,a+n+1);
    int l = 1, r = n;
    while (l <= r) {
        int mid = (l+r) >> 1;
        if (check(mid)) {
            res = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    check(res);
    cout << res << '\n';
    for (int i=1;i<=m;i++) {
        for (int x : lis[i]) cout << x << ' ';
        cout << 0 << '\n';
    }
}

signed main() {
//    freopen("test.inp","r",stdin);
//    freopen("test.out","w",stdout);
    FAST
    int t=1;
//    cin >> t;
    while (t--) sol();
}
#Verdict Execution timeMemoryGrader output
Fetching results...