#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n, d, m;
vector<pii> vect;
vector<vector<int> > ans;
bool check(int mid){
ans.clear();
ans.resize(n);
int c=0;
for (int i=0, p=0, j; i<n; ++i){
for (j=p; j<min(m, p+mid); ++j){
if (vect[j].fi<=i){
if (i-vect[j].fi+1>d)return 0;
else ans[i].pb(vect[j].se), ++c;
}
else break;
}
p=j;
}
return (c==m);
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>d>>m;
vect.resize(m);
for (int i=0; i<m; ++i)cin>>vect[i].fi, --vect[i].fi, vect[i].se=i+1;
sort(vect.begin(), vect.end());
int low=0, high=m+1;
while (low+1<high){
int mid=(low+high)/2;
if (check(mid))high=mid;
else low=mid;
}
check(high);
cout<<high<<"\n";
for (auto a:ans){
for (auto b:a)cout<<b<<" ";
cout<<"0\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |