#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
#define deb1(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl;
#define ff first
#define ss second
#define pb push_back
int N, D, M;
vector<vector<int>> a;
bool ok(int m) {
vector<int> av(N + 1, m);
for (int i = 1; i <= N - D; i++) {
int jbs = a[i].size();
for (int j = i; j <= i + D && jbs; j++) {
if (av[j] >= jbs) {
av[j] -= jbs;
jbs = 0;
}
else {
jbs -= av[j];
av[j] = 0;
}
}
if (jbs) return 0;
}
return 1;
}
void show(int m) {
for (int i = 1, cd = 1; i <= N; i++) {
int tm = m;
while (tm--) {
while (cd <= N && a[cd].empty()) cd++;
if (cd > N) break;
cout << a[cd].back() << " ";
a[cd].pop_back();
}
cout << "0\n";
}
}
signed main() {
FAST;
cin >> N >> D >> M;
a = vector<vector<int>>(N + 1);
for (int i = 1; i <= M; i++) {
int x; cin >> x;
a[x].pb(i);
}
int l = 1, r = 1e6 + 7, ans = M;
while (l <= r) {
int m = l + (r - l) / 2;
if (ok(m)) ans = m, r = m - 1;
else l = m + 1;
}
cout << ans << "\n";
show(ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1992 KB |
Output is correct |
2 |
Correct |
19 ms |
1968 KB |
Output is correct |
3 |
Correct |
19 ms |
2024 KB |
Output is correct |
4 |
Correct |
19 ms |
1992 KB |
Output is correct |
5 |
Correct |
21 ms |
2172 KB |
Output is correct |
6 |
Correct |
23 ms |
2088 KB |
Output is correct |
7 |
Correct |
19 ms |
2040 KB |
Output is correct |
8 |
Correct |
20 ms |
2084 KB |
Output is correct |
9 |
Correct |
27 ms |
5436 KB |
Output is correct |
10 |
Correct |
26 ms |
5364 KB |
Output is correct |
11 |
Correct |
20 ms |
1980 KB |
Output is correct |
12 |
Correct |
41 ms |
3668 KB |
Output is correct |
13 |
Correct |
60 ms |
6596 KB |
Output is correct |
14 |
Correct |
111 ms |
8360 KB |
Output is correct |
15 |
Correct |
99 ms |
9736 KB |
Output is correct |
16 |
Correct |
147 ms |
12408 KB |
Output is correct |
17 |
Correct |
177 ms |
15444 KB |
Output is correct |
18 |
Correct |
159 ms |
14924 KB |
Output is correct |
19 |
Correct |
188 ms |
18740 KB |
Output is correct |
20 |
Correct |
179 ms |
15496 KB |
Output is correct |