Submission #1199490

#TimeUsernameProblemLanguageResultExecution timeMemory
1199490WarinchaiJob Scheduling (CEOI12_jobs)C++20
100 / 100
233 ms22144 KiB
#include<bits/stdc++.h>
using namespace std;
int ar[100005];
vector<int>v[100005];
int n,d,m;
vector<vector<int>>ans;
bool check(int md){
    deque<pair<int,int>>dq;
    ans.clear();
    for(int i=1;i<=n;i++){
        for(int j=0;j<ar[i];j++)dq.push_back({i,v[i][j]});
        vector<int>temp;
        for(int j=0;j<md;j++){
            if(dq.empty())break;
            int x=i-dq.front().first;
            if(x>d)return false;
            temp.push_back(dq.front().second);
            dq.pop_front();
        }
        temp.push_back(0);
        ans.push_back(temp);
    }
    if(!dq.empty())return false;
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>d>>m;
    for(int i=1;i<=m;i++){
        int x;cin>>x;
        ar[x]++;
        v[x].push_back(i);
    }
    int st=1,en=m,tans=m;
    while(st<=en){
        int md=(st+en)/2;
        if(check(md)){
            en=md-1;
            tans=md;
        }else{
            st=md+1;
        }
    }
    check(tans);
    cout<<tans<<"\n";
    int cnt=0;
    for(auto x:ans){
        for(auto y:x){
            if(y==0)cout<<"0\n";
            else cout<<y<<" ";
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...