Submission #1306964

#TimeUsernameProblemLanguageResultExecution timeMemory
1306964daniutaiyangJob Scheduling (CEOI12_jobs)C++20
100 / 100
481 ms15008 KiB
#include<bits/stdc++.h>
using namespace std;
int days, delay, requests, ans, request_dates[1000005];
map<int,vector<int> > requests_per_day;
bool check(int machines){
    priority_queue<int, vector<int>, greater<int> > pq;
    for(int i=1; i<=days; i++){
        if(requests_per_day.find(i)!=requests_per_day.end()) for(auto j : requests_per_day[i]) pq.push(i);
        int stuff = 0;
        while(!pq.empty()&&stuff<machines){
            int z = pq.top();
            if(i-z>delay) return false;
            pq.pop();
            stuff++;
        }
    }
    return pq.empty();
}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> days >> delay >> requests;
    for(int i=1; i<=requests; i++){
        cin >> request_dates[i];
        requests_per_day[request_dates[i]].push_back(i);
    }
    int lo = 1, hi = requests;
    while(lo<=hi){
        int mid = (lo+hi)/2;
        if(check(mid)){
            ans = mid;
            hi = mid-1;
        }else lo = mid+1;
    }
    cout << ans << '\n';
    priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > pq;
    for(int i=1; i<=days; i++){
        if(requests_per_day.find(i)!=requests_per_day.end()) for(auto j : requests_per_day[i]) pq.push(make_pair(i,j));
        int stuff = 0;
        while(!pq.empty()&&stuff<ans){
            int z = pq.top().second;
            cout << z << ' ';
            pq.pop();
            stuff++;
        }
        cout << "0\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...