제출 #740771

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, d, m;
    cin >> n >> d >> m;

    vector<vector<int>> J(n);
    for(int i=0; i<m; i++) {
        int c; cin >> c;
        J[c-1].push_back(i+1);
    }

    int lo=0, hi=m;
    while(lo < hi) {
        int mid = (lo + hi) / 2;

        int t = 0;
        int rem=mid;
        bool works=true;
        for(int i=0; i<n && works; i++) {
            int count = J[i].size();
            count -= rem;
            t++;
            rem=mid;
            if(count<0) continue;

            while(count>0) {
                count-=mid;
                if(count<0) rem=-count;
                else t++;
            }

            if(t-i>d) works=false;
        }

        if(works) hi = mid;
        else lo = mid+1;
    }

    cout << lo << "\n";
    int count=0;
    int acc=0;
    for(int i=0; i<n; i++) {
        for(int j : J[i]) {
            if(count>=lo) {
                cout << 0 << "\n" << j << " ";
                acc++;
                count=1;
            }
            else {
                cout << j << " ";
                count++;
            }
        }
        if(acc<=i) {
            cout << 0 << "\n";
            count=0;
            acc++;
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...