#include <iostream>
#include <vector>
#include <queue>
std::vector<int> jobs[100001];
int n, m, d;
bool check(int a){
int max_queue = a * d;
int len = 0;
for(int i = 0; i < n; i++){
len += jobs[i].size();
if(len > max_queue) return false;
len -= a;
if(len < 0) len = 0;
}
return true;
}
int main(){
std::cin >> n >> d >> m;
d++;
for(int i = 0; i < m; i++){
int a;
std::cin >> a;
a--;
jobs[a].push_back(i+1);
}
int lower = 0;
int higher = m;
while(higher > lower + 1){
int mid = (higher + lower) / 2;
if(check(mid)) higher = mid;
else lower = mid;
}
std::cout << higher << std::endl;
std::queue<int> jbs;
for(int i = 0; i < n; i++){
for(int a: jobs[i]){
jbs.push(a);
}
for(int j = 0; j < higher; j++){
if(jbs.empty()) break;
std::cout << jbs.front() << " ";
jbs.pop();
}
std::cout << 0 << std::endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
4304 KB |
Output is correct |
2 |
Correct |
23 ms |
4304 KB |
Output is correct |
3 |
Correct |
24 ms |
4300 KB |
Output is correct |
4 |
Correct |
26 ms |
4284 KB |
Output is correct |
5 |
Correct |
23 ms |
4308 KB |
Output is correct |
6 |
Correct |
23 ms |
4304 KB |
Output is correct |
7 |
Correct |
22 ms |
4304 KB |
Output is correct |
8 |
Correct |
22 ms |
4408 KB |
Output is correct |
9 |
Correct |
98 ms |
4452 KB |
Output is correct |
10 |
Correct |
98 ms |
4436 KB |
Output is correct |
11 |
Correct |
19 ms |
4188 KB |
Output is correct |
12 |
Correct |
38 ms |
5624 KB |
Output is correct |
13 |
Correct |
47 ms |
7768 KB |
Output is correct |
14 |
Correct |
151 ms |
9548 KB |
Output is correct |
15 |
Correct |
78 ms |
10372 KB |
Output is correct |
16 |
Correct |
150 ms |
12368 KB |
Output is correct |
17 |
Correct |
140 ms |
14416 KB |
Output is correct |
18 |
Correct |
182 ms |
14224 KB |
Output is correct |
19 |
Correct |
227 ms |
15240 KB |
Output is correct |
20 |
Correct |
178 ms |
14416 KB |
Output is correct |