#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d, m;
cin >> n >> d >> m;
vector<int> v[n + 1];
for (int i = 1; i <= m; i++)
{
int x;
cin >> x;
v[x].push_back(i);
}
int l = 1, r = m;
while (l < r)
{
int mid = (l + r) >> 1;
queue<array<int, 2>> q;
int ok = 1;
for (int i = 1; i <= n; i++)
{
for (int x : v[i]) q.push({x, i});
int k = mid;
while (!q.empty() && k--) q.pop();
if (!q.empty() && q.front()[1] + d == i)
{
ok = 0;
break;
}
}
ok &= q.empty();
if (ok) r = mid;
else l = mid + 1;
}
cout << l << '\n';
queue<array<int, 2>> q;
for (int i = 1; i <= n; i++)
{
for (int x : v[i]) q.push({x, i});
int k = l;
while (!q.empty() && k--)
{
cout << q.front()[0] << ' ';
q.pop();
}
cout << 0 << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
4032 KB |
Output is correct |
2 |
Correct |
39 ms |
4008 KB |
Output is correct |
3 |
Correct |
34 ms |
3792 KB |
Output is correct |
4 |
Correct |
34 ms |
4048 KB |
Output is correct |
5 |
Correct |
34 ms |
3840 KB |
Output is correct |
6 |
Correct |
37 ms |
4208 KB |
Output is correct |
7 |
Correct |
37 ms |
4036 KB |
Output is correct |
8 |
Correct |
34 ms |
3792 KB |
Output is correct |
9 |
Correct |
39 ms |
5048 KB |
Output is correct |
10 |
Correct |
34 ms |
4956 KB |
Output is correct |
11 |
Correct |
34 ms |
2500 KB |
Output is correct |
12 |
Correct |
61 ms |
4596 KB |
Output is correct |
13 |
Correct |
84 ms |
7800 KB |
Output is correct |
14 |
Correct |
121 ms |
11008 KB |
Output is correct |
15 |
Correct |
142 ms |
11700 KB |
Output is correct |
16 |
Correct |
170 ms |
15332 KB |
Output is correct |
17 |
Correct |
207 ms |
18716 KB |
Output is correct |
18 |
Correct |
244 ms |
17952 KB |
Output is correct |
19 |
Correct |
283 ms |
21416 KB |
Output is correct |
20 |
Correct |
232 ms |
18800 KB |
Output is correct |