#include<bits/stdc++.h>
using namespace std;
int ar[1100005];
vector<int>v[1100005];
int n,d,m;
int mxd=0;
vector<vector<int>>ans;
bool check(int md){
deque<pair<int,int>>dq;
ans.clear();
for(int i=1;i<=mxd;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);
}
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>d>>m;
mxd=m+n;
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)cout<<y<<" ";
cout<<"\n";
cnt++;
if(cnt==n)return 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |