#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 1, M = 1e6 + 1;
int n, d, m;
pair<int, int> a[M];
vector<int> ans[N];
bool good(int k) {
int j = 1;
for (int i = 1; i <= n; ++i) {
for (int x = 1; x <= k; ++x) {
if (a[j].first > i) break;
if (a[j].first + d < i) return false;
if (j == m) return true;
++j;
}
}
return false;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> d >> m;
for (int i = 1; i <= m; ++i) {
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1, a + 1 + m);
int l = 0, r = m + 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (good(mid)) r = mid;
else l = mid;
}
cout << r << '\n';
for (int i = 1, j = 1; i <= n; ++i) {
for (int x = 1; x <= r && j <= m; ++x, ++j) {
if (a[j].first > i) break;
ans[i].push_back(a[j].second);
}
for (int k: ans[i]) cout << k << ' ';
cout << "0\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
4564 KB |
Output is correct |
2 |
Correct |
19 ms |
4608 KB |
Output is correct |
3 |
Correct |
19 ms |
4564 KB |
Output is correct |
4 |
Correct |
19 ms |
4564 KB |
Output is correct |
5 |
Correct |
18 ms |
4556 KB |
Output is correct |
6 |
Correct |
19 ms |
4564 KB |
Output is correct |
7 |
Correct |
18 ms |
4564 KB |
Output is correct |
8 |
Correct |
18 ms |
4588 KB |
Output is correct |
9 |
Correct |
36 ms |
4700 KB |
Output is correct |
10 |
Correct |
29 ms |
4684 KB |
Output is correct |
11 |
Correct |
28 ms |
4564 KB |
Output is correct |
12 |
Correct |
52 ms |
6540 KB |
Output is correct |
13 |
Correct |
77 ms |
9032 KB |
Output is correct |
14 |
Correct |
115 ms |
11132 KB |
Output is correct |
15 |
Correct |
132 ms |
11992 KB |
Output is correct |
16 |
Correct |
160 ms |
14136 KB |
Output is correct |
17 |
Correct |
203 ms |
18044 KB |
Output is correct |
18 |
Correct |
212 ms |
18512 KB |
Output is correct |
19 |
Correct |
251 ms |
20200 KB |
Output is correct |
20 |
Correct |
189 ms |
18060 KB |
Output is correct |