#include <bits/stdc++.h>
using namespace std;
int n,delay,m; 
vector<pair<int,int>> vp;
bool alg(int x){
    for (int day=1;day<=n;day++) {
        int idx=day*x;
        if (idx>=m) return true;
        if (vp[idx-1].first+delay<day) return false;
    }
    return true;
}
int main(){
  
    cin>>n>>delay>>m;
    for (int i=0;i<m;i++) {
        int day;
        cin>>day;
        vp.push_back({day,i+1});
    }
    sort(vp.begin(),vp.end());
    // for (auto x: vp) cout<<x.first<<" "<<x.second<<"\n";
    // cout<<"\n";
    int low=1,high=m;
    while (low<high){
        int mid=(low+high)/2;
        if (alg(mid)) high=mid;
        else low=mid+1;
    }
    cout<<low<<"\n";
    for (int i=0;i<n;i++) {
        for (int j=0;j<low;j++) {
            int idx=i*low+j;
            if (idx>=m) {
                break;
            }
            cout<<vp[idx].second<<" ";
        }
        cout<<"0\n";
    }
    
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |