#include <bits/stdc++.h>
using namespace std;
#define MAXX 1000005
#define ll long long
pair<int,int>j[MAXX];
int n,m,d;
bool check(int num){
int cur=0;
for(int k=0;k<n;k++) {
for(int i=0;i<num;i++) {
if(cur<m && j[cur].first<=k+1 && j[cur].first+d>=k+1)cur++;
else break;
}
}
if(cur==m)return 1;
else return 0;
}
int main(){
cin>>n>>d>>m;
for(int i=0;i<m;i++){
cin>>j[i].first;
j[i].second=i+1;
}
sort(j,j+m);
int r=m,l=0,mid,res=-1;
while(l<=r) {
mid=(l+r)/2;
if(check(mid)) {
res=mid;
r=mid-1;
}
else l=mid+1;
}
int cur=0;
cout<<res<<endl;
for(ll k=0;k<n;k++){
for(ll i=0;i<res;i++){
if(cur<m && j[cur].first<=k+1 && j[cur].first+d>=k+1) {
cout<<j[cur].second<<" ";
cur++;
}
else break;
}
cout<<0<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
1604 KB |
Output is correct |
2 |
Correct |
59 ms |
1600 KB |
Output is correct |
3 |
Correct |
55 ms |
1640 KB |
Output is correct |
4 |
Correct |
53 ms |
1604 KB |
Output is correct |
5 |
Correct |
53 ms |
1668 KB |
Output is correct |
6 |
Correct |
52 ms |
1564 KB |
Output is correct |
7 |
Correct |
52 ms |
1732 KB |
Output is correct |
8 |
Correct |
53 ms |
1688 KB |
Output is correct |
9 |
Correct |
207 ms |
1776 KB |
Output is correct |
10 |
Correct |
200 ms |
1828 KB |
Output is correct |
11 |
Correct |
50 ms |
1648 KB |
Output is correct |
12 |
Correct |
98 ms |
3140 KB |
Output is correct |
13 |
Correct |
151 ms |
4572 KB |
Output is correct |
14 |
Correct |
238 ms |
6184 KB |
Output is correct |
15 |
Correct |
254 ms |
7500 KB |
Output is correct |
16 |
Correct |
349 ms |
9108 KB |
Output is correct |
17 |
Correct |
405 ms |
10492 KB |
Output is correct |
18 |
Correct |
417 ms |
12108 KB |
Output is correct |
19 |
Correct |
640 ms |
13648 KB |
Output is correct |
20 |
Correct |
389 ms |
10488 KB |
Output is correct |