// Jai Shree Ram
#include<bits/stdc++.h>
using namespace std;
/* Abhi-Atg */
#define array int n;cin >> n;vector<long long> v(n);f(i,0,n)cin >> v[i];
#define out(_) for (auto &it :_){cout << it << " " ;}cout<<endl;
#define f(i,l,r) for(int i=l;i<r;i++)
#define ff(i,r,l) for(int i=r;i>=l;i--)
#define pb push_back
#define mod 1000000007
#define INDIA 998244353
#define ll long long
#define all(v) v.begin(),v.end()
#define dbg cout << "Bharat\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define minus cout << "-1\n"
void solve(){
int n,d,m;cin >> n >> d >> m;
vector<pair<int,int>> v(m);
f(i,0,m){
cin >> v[i].first;
v[i].second=i+1;
}
sort(all(v));
int l=1,r=m;
while(l<=r){
int mid=(l+r)/2;
int day=1;
int ind=0;
bool flag=true;
while(day<=n && ind<m){
int cnt=0;
vector<int> ans;
if(v[ind].first+d<day){
flag=false;break;
}
while(ind<m && cnt<mid && v[ind].first+d>=day){
cnt++;
ind++;
}
day++;
}
if(flag)r=mid-1;
else l=mid+1;
}
cout<<l<<"\n";
vector<vector<int>> ans;
int day=1;
int ind=0;
while(day<=n && ind<m){
int cnt=0;
vector<int> ans;
while(ind<m && cnt<l && v[ind].first+d>=day){
cnt++;
ans.push_back(v[ind++].second);
}
ans.push_back(0);
f(i,0,ans.size()){
cout<<ans[i]<<" \n"[i==ans.size()-1];
}
day++;
}
while(day<=n){
cout<<0<<"\n";
day++;
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(nullptr);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
// freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
int t=1;
// cin >> t;
for(int _=1;_<=t;_++){
// cout<<"Case #"<<_<<": ";
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |