#include <bits/stdc++.h>
using namespace std;
constexpr int N = 100005;
constexpr int M = 1000005;
vector<int> ids[N];
int n, d, m;
bool test(int c, bool print=false) {
queue<pair<int, int>> q; // stores {day, id}
for (int i = 1; i <= n; ++i) {
for (const int id : ids[i]) q.emplace(i, id);
for (int j = 0; j < c && !q.empty(); ++j) {
if (print) printf("%d ", q.front().second);
q.pop();
}
if (print) printf("0\n");
if (!q.empty() && q.front().first <= i-d) return false;
}
return q.empty();
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> d >> m;
for (int x, i = 1; i <= m; ++i) {
cin >> x; ids[x].push_back(i);
}
int l = 1, r = m;
while (l < r) {
const int md = l + (r-l)/2;
if (test(md)) r = md;
else l = md+1;
}
printf("%d\n", l);
test(l, true);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
4504 KB |
Output is correct |
2 |
Correct |
32 ms |
4428 KB |
Output is correct |
3 |
Correct |
30 ms |
4428 KB |
Output is correct |
4 |
Correct |
36 ms |
4480 KB |
Output is correct |
5 |
Correct |
31 ms |
4564 KB |
Output is correct |
6 |
Correct |
32 ms |
4460 KB |
Output is correct |
7 |
Correct |
30 ms |
4452 KB |
Output is correct |
8 |
Correct |
31 ms |
4540 KB |
Output is correct |
9 |
Correct |
33 ms |
4100 KB |
Output is correct |
10 |
Correct |
37 ms |
4124 KB |
Output is correct |
11 |
Correct |
36 ms |
3832 KB |
Output is correct |
12 |
Correct |
58 ms |
5104 KB |
Output is correct |
13 |
Correct |
89 ms |
6828 KB |
Output is correct |
14 |
Correct |
126 ms |
8380 KB |
Output is correct |
15 |
Correct |
137 ms |
9036 KB |
Output is correct |
16 |
Correct |
176 ms |
10720 KB |
Output is correct |
17 |
Correct |
208 ms |
12680 KB |
Output is correct |
18 |
Correct |
250 ms |
12664 KB |
Output is correct |
19 |
Correct |
286 ms |
13516 KB |
Output is correct |
20 |
Correct |
206 ms |
12608 KB |
Output is correct |