#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long
#define pii pair<int, int>
#define soclose 1e-9
int N, K, M;
vector<pii> a;
vector<int> b;
bool f(int m) {
int pos = 0;
for (int day = 1; day <= N; ++day) {
for (int j = 0; j < m; ++j) {
if (a[pos].first > day) break;
if (a[pos].first + K < day) return false;
else pos++;
if (pos == M) return true;
}
}
return false;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("angry.in", "r", stdin);
//freopen("angry.out", "w", stdout);
cin >> N >> K >> M;
a.resize(M);
for (int i = 0; i < M; ++i) {
cin >> a[i].first;
a[i].second = i + 1;
}
sort(all(a));
b.assign(M, 0);
int l = 0, r = M;
while (r - l > 1) {
int m = (l + r) / 2;
if (f(m)) r = m;
else l = m;
}
cout << r << "\n";
vector<int> ans[N];
int pos = 0;
for (int day = 1; day <= N; ++day) {
for (int j = 0; j < r; ++j) {
if (a[pos].first > day) break;
if (a[pos].first + K >= day) {
ans[day - 1].push_back(a[pos++].second);
}
if (pos == M) break;
}
if (pos == M) break;
}
for (int i = 0; i < N; ++i) {
for (int x : ans[i]) cout << x << " ";
cout << "0\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2772 KB |
Output is correct |
2 |
Correct |
18 ms |
2780 KB |
Output is correct |
3 |
Correct |
19 ms |
2824 KB |
Output is correct |
4 |
Correct |
19 ms |
2784 KB |
Output is correct |
5 |
Correct |
19 ms |
2832 KB |
Output is correct |
6 |
Correct |
24 ms |
2772 KB |
Output is correct |
7 |
Correct |
18 ms |
2772 KB |
Output is correct |
8 |
Correct |
18 ms |
2796 KB |
Output is correct |
9 |
Correct |
30 ms |
5072 KB |
Output is correct |
10 |
Correct |
28 ms |
5076 KB |
Output is correct |
11 |
Correct |
25 ms |
2584 KB |
Output is correct |
12 |
Correct |
52 ms |
4964 KB |
Output is correct |
13 |
Correct |
76 ms |
7812 KB |
Output is correct |
14 |
Correct |
110 ms |
10616 KB |
Output is correct |
15 |
Correct |
127 ms |
11588 KB |
Output is correct |
16 |
Correct |
156 ms |
14348 KB |
Output is correct |
17 |
Correct |
195 ms |
18660 KB |
Output is correct |
18 |
Correct |
218 ms |
19504 KB |
Output is correct |
19 |
Correct |
234 ms |
23612 KB |
Output is correct |
20 |
Correct |
183 ms |
18552 KB |
Output is correct |