#include <bits/stdc++.h>
using namespace std;
#define int long long int
bool check(vector<int> a, int mi, int n, int d) {
int i = 0;
while(a.size() && i < n) {
for (int j = 0; j < mi; j++) {
if (a.empty()) {
break;
}
if (i+1 > a.back()+d) {
return 0;
}
a.pop_back();
}
i++;
}
return a.size() == 0;
}
void solve() {
int n, d, m;
cin >> n >> d >> m;
vector<int> a(m);
vector<pair<int, int>> ans;
for (int i = 0; i < m; i++) {
cin >> a[i];
ans.push_back({a[i], i});
}
sort(a.rbegin(), a.rend());
sort(ans.begin(), ans.end());
int l = 1, r = n;
while(l < r) {
int mi = (l+r)/2;
if (check(a, mi, n, d)) {
r = mi;
} else {
l = mi+1;
}
}
cout << l << endl;
int j = 0;
for (int i = 0; i < n; i++) {
int c = l;
while(j < m && c--) {
cout << ans[j].second+1 << " ";
j++;
}
cout << 0 << endl;
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
4308 KB |
Output isn't correct |
2 |
Incorrect |
24 ms |
4304 KB |
Output isn't correct |
3 |
Incorrect |
24 ms |
4304 KB |
Output isn't correct |
4 |
Incorrect |
24 ms |
4304 KB |
Output isn't correct |
5 |
Incorrect |
24 ms |
4304 KB |
Output isn't correct |
6 |
Incorrect |
24 ms |
4308 KB |
Output isn't correct |
7 |
Incorrect |
24 ms |
4312 KB |
Output isn't correct |
8 |
Incorrect |
28 ms |
4496 KB |
Output isn't correct |
9 |
Correct |
119 ms |
4552 KB |
Output is correct |
10 |
Correct |
160 ms |
4480 KB |
Output is correct |
11 |
Correct |
25 ms |
4556 KB |
Output is correct |
12 |
Correct |
58 ms |
8640 KB |
Output is correct |
13 |
Correct |
73 ms |
12880 KB |
Output is correct |
14 |
Correct |
122 ms |
17376 KB |
Output is correct |
15 |
Incorrect |
131 ms |
21404 KB |
Output isn't correct |
16 |
Correct |
172 ms |
26688 KB |
Output is correct |
17 |
Correct |
234 ms |
30540 KB |
Output is correct |
18 |
Runtime error |
211 ms |
34048 KB |
Memory limit exceeded |
19 |
Runtime error |
318 ms |
38252 KB |
Memory limit exceeded |
20 |
Correct |
190 ms |
30496 KB |
Output is correct |