#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
void solve(){
int n, D, m;
cin >> n >> D >> m;
vector<int> a(m+1);
vector<vector<int>> b(n+1);
for(int i = 1; i <= m; i++){
cin >> a[i];
b[a[i]].push_back(i);
}
vector<vector<int>> ans(n+1);
auto check = [&](int x) -> bool{
queue<int> q;
for(int i = 1; i <= n; i++){
ans[i].clear();
for(int j : b[i]){
q.push(j);
}
int cnt = x;
while(!q.empty() && cnt > 0){
cnt--;
int j = q.front();
q.pop();
ans[i].push_back(j);
if(a[j]+D < i) return 0;
}
}
return q.empty();
};
int l = 1, r = m, mid;
while(l <= r){
mid = (l+r)/2;
if(check(mid)){
r = mid-1;
}else{
l = mid+1;
}
}
check(l);
cout << l << "\n";
for(int i = 1; i <= n; i++){
for(int j : ans[i]){
cout << j << " ";
}
cout << "0\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3536 KB |
Output is correct |
2 |
Correct |
18 ms |
3588 KB |
Output is correct |
3 |
Correct |
18 ms |
3544 KB |
Output is correct |
4 |
Correct |
18 ms |
3548 KB |
Output is correct |
5 |
Correct |
19 ms |
3600 KB |
Output is correct |
6 |
Correct |
18 ms |
3544 KB |
Output is correct |
7 |
Correct |
18 ms |
3548 KB |
Output is correct |
8 |
Correct |
19 ms |
3548 KB |
Output is correct |
9 |
Correct |
23 ms |
7504 KB |
Output is correct |
10 |
Correct |
22 ms |
7772 KB |
Output is correct |
11 |
Correct |
21 ms |
2896 KB |
Output is correct |
12 |
Correct |
43 ms |
5376 KB |
Output is correct |
13 |
Correct |
63 ms |
9040 KB |
Output is correct |
14 |
Correct |
99 ms |
12628 KB |
Output is correct |
15 |
Correct |
106 ms |
13396 KB |
Output is correct |
16 |
Correct |
142 ms |
17232 KB |
Output is correct |
17 |
Correct |
176 ms |
22096 KB |
Output is correct |
18 |
Correct |
191 ms |
21072 KB |
Output is correct |
19 |
Correct |
217 ms |
26960 KB |
Output is correct |
20 |
Correct |
184 ms |
22096 KB |
Output is correct |