#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,d,m;
cin>>n>>d>>m;
pair<long long,long long> niza[m];
for(long long i=0; i<m; i++)
{
cin>>niza[i].first;
niza[i].second=i+1;
}
sort(niza,niza+m);
long long b=0,e=m+1;
long long res=0;
while(b<=e)
{
long long mid=(b+e)/2;
long long cnt=0;
long long day=1;
long long og=0;
bool flag=true;
for(long long i=0; i<m; i++)
{
cnt++;
if(cnt>mid || niza[i].first>day || niza[i].first-niza[og].first>d)
{
cnt=1;
og=i;
day++;
}
if(day-niza[i].first>d || day>n)
{
flag=false;
break;
}
}
if(flag)
{
res=mid;
e=mid-1;
}
else b=mid+1;
}
cout<<res<<endl;
long long cnt=0;
long long day=1;
long long og=0;
vector<long long> ress[n+1];
for(long long i=0; i<m; i++)
{
cnt++;
if(cnt>res || (niza[i].first>day && niza[i].first-niza[og].first>d))
{
cnt=1;
og=i;
day++;
}
ress[day].push_back(niza[i].second);
}
for(long long i=1; i<=n; i++)
{
for(auto x:ress[i])cout<<x<<" ";
cout<<0<<endl;
}
return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
3928 KB |
Output isn't correct |
2 |
Incorrect |
23 ms |
3936 KB |
Output isn't correct |
3 |
Incorrect |
23 ms |
3932 KB |
Output isn't correct |
4 |
Incorrect |
23 ms |
3924 KB |
Output isn't correct |
5 |
Incorrect |
23 ms |
3932 KB |
Output isn't correct |
6 |
Incorrect |
24 ms |
3936 KB |
Output isn't correct |
7 |
Incorrect |
23 ms |
3856 KB |
Output isn't correct |
8 |
Incorrect |
27 ms |
4040 KB |
Output isn't correct |
9 |
Correct |
119 ms |
6228 KB |
Output is correct |
10 |
Correct |
116 ms |
6228 KB |
Output is correct |
11 |
Correct |
21 ms |
3956 KB |
Output is correct |
12 |
Correct |
43 ms |
7504 KB |
Output is correct |
13 |
Correct |
70 ms |
12116 KB |
Output is correct |
14 |
Correct |
97 ms |
16464 KB |
Output is correct |
15 |
Correct |
106 ms |
17476 KB |
Output is correct |
16 |
Correct |
140 ms |
22096 KB |
Output is correct |
17 |
Correct |
164 ms |
29688 KB |
Output is correct |
18 |
Correct |
185 ms |
29780 KB |
Output is correct |
19 |
Runtime error |
264 ms |
34576 KB |
Memory limit exceeded |
20 |
Correct |
159 ms |
29840 KB |
Output is correct |