Submission #1283069

#TimeUsernameProblemLanguageResultExecution timeMemory
1283069vk3601hJob Scheduling (CEOI12_jobs)C++20
100 / 100
160 ms26396 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int days_num, delay, jobs_num;
    cin >> days_num >> delay >> jobs_num;

    vector<vector<int>> jobs(days_num);
    for (int i = 0; i < jobs_num; i++){
        int date;
        cin >> date;
        jobs[date - 1].push_back(i);
    }

    auto check = [&](int res, vector<vector<int>> &tmp_schedule) -> bool {
        queue<pair<int, int>> cands;

        for (int i = 0; i < days_num; i++){
            for (int job : jobs[i]) cands.push({job, i});

            for (int j = 0; !cands.empty() && j < res; j++){
                int job = cands.front().first;
                int date = cands.front().second;
                cands.pop();

                if (date + delay < i) return false;
                tmp_schedule[i].push_back(job);
            }
        }

        return cands.empty();
    };

    vector<vector<int>> final_schedule(days_num);
    int low = 0, high = jobs_num, ans = -1;
    while (low <= high){
        int mid = (low + high) / 2;

        vector<vector<int>> tmp_schedule(days_num);
        if (check(mid, tmp_schedule)){
            high = mid - 1;
            ans = mid;
            final_schedule = move(tmp_schedule);
        }
        else low = mid + 1;
    }

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