#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, d, m;
pair < int, int > a[N];
inline bool check(int x){
int i = 1, day = 0;
while(i <= m){
day += 1;
int j = i;
while(j <= min(m, i + x - 1) && day >= a[j].first){
if(a[j].first + d < day){
return false;
}
j += 1;
}
i = j;
}
return true;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> d >> m;
for(int i = 1; i <= m; i++){
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1, a + m + 1);
int l = 1, r = m;
while(l < r){
int mid = (r + l) >> 1;
if(check(mid)){
r = mid;
}
else{
l = mid + 1;
}
}
cout << l << "\n";
int i = 1, day = 0;
for(int it = 1; it <= n; it++){
day += 1;
int j = i;
while(j <= min(m, i + l - 1) && day >= a[j].first){
cout << a[j].second << " ";
j += 1;
}
cout << "0\n";
i = j;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1792 KB |
Output is correct |
2 |
Correct |
19 ms |
1792 KB |
Output is correct |
3 |
Correct |
34 ms |
1784 KB |
Output is correct |
4 |
Correct |
28 ms |
1792 KB |
Output is correct |
5 |
Correct |
37 ms |
1784 KB |
Output is correct |
6 |
Correct |
19 ms |
1784 KB |
Output is correct |
7 |
Correct |
29 ms |
1656 KB |
Output is correct |
8 |
Correct |
33 ms |
1792 KB |
Output is correct |
9 |
Correct |
29 ms |
1920 KB |
Output is correct |
10 |
Correct |
35 ms |
2040 KB |
Output is correct |
11 |
Correct |
36 ms |
1784 KB |
Output is correct |
12 |
Correct |
66 ms |
3192 KB |
Output is correct |
13 |
Correct |
91 ms |
4600 KB |
Output is correct |
14 |
Correct |
129 ms |
6136 KB |
Output is correct |
15 |
Correct |
157 ms |
7544 KB |
Output is correct |
16 |
Correct |
180 ms |
9068 KB |
Output is correct |
17 |
Correct |
214 ms |
10620 KB |
Output is correct |
18 |
Correct |
250 ms |
11952 KB |
Output is correct |
19 |
Correct |
286 ms |
13752 KB |
Output is correct |
20 |
Correct |
233 ms |
10588 KB |
Output is correct |