// https://oj.uz/problem/view/CEOI12_jobs
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
// n,d<=1e5, m<=1e6
int n, d, m;
struct J {
int s, idx;
};
J jobs[1000005];
// return if x machine is enough
bool check(int x, bool print) {
int j = 0; // job index
for (int i = 1; i <= n; i++) {
// do jobs
int cnt = 0;
while(cnt < x && j < m && jobs[j].s <= i) {
if (jobs[j].s + d < i) // already expired
return false;
if (print)
printf("%d ", jobs[j].idx);
cnt++;
j++;
}
if (print)
printf("0\n");
}
return true;
}
inline bool cmp(J &a, J &b) {return a.s < b.s;}
inline int read() {
int r = 0;
bool start = false, neg = false;
while (true) {
char c = getchar();
if (!start && c != '-' && (c < '0' || c > '9')) continue;
start = true;
if (c == '-') neg = true;
else if (c >= '0' && c <= '9')
r = r * 10 + c - '0';
else
break;
}
return r;
}
int main() {
scanf("%d %d %d", &n, &d, &m);
for (int i = 0; i < m; i++) {
jobs[i].s = read();
jobs[i].idx = i+1;
}
sort(jobs, jobs+m, cmp);
int low = 1, high = m;
while (low < high) {
int mid = (low + high) / 2;
if (check(mid, false))
high = mid;
else
low = mid+1;
}
printf("%d\n", low);
check(low, true);
return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
answer is 2
*/
Compilation message
jobs.cpp: In function 'int read()':
jobs.cpp:42:25: warning: variable 'neg' set but not used [-Wunused-but-set-variable]
42 | bool start = false, neg = false;
| ^~~
jobs.cpp: In function 'int main()':
jobs.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%d %d %d", &n, &d, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1580 KB |
Output is correct |
2 |
Correct |
17 ms |
1572 KB |
Output is correct |
3 |
Correct |
16 ms |
1576 KB |
Output is correct |
4 |
Correct |
15 ms |
1600 KB |
Output is correct |
5 |
Correct |
15 ms |
1620 KB |
Output is correct |
6 |
Correct |
16 ms |
1620 KB |
Output is correct |
7 |
Correct |
15 ms |
1668 KB |
Output is correct |
8 |
Correct |
17 ms |
1644 KB |
Output is correct |
9 |
Correct |
21 ms |
1748 KB |
Output is correct |
10 |
Correct |
22 ms |
1852 KB |
Output is correct |
11 |
Correct |
19 ms |
1580 KB |
Output is correct |
12 |
Correct |
40 ms |
3108 KB |
Output is correct |
13 |
Correct |
60 ms |
4528 KB |
Output is correct |
14 |
Correct |
90 ms |
6088 KB |
Output is correct |
15 |
Correct |
104 ms |
7576 KB |
Output is correct |
16 |
Correct |
136 ms |
9036 KB |
Output is correct |
17 |
Correct |
147 ms |
10492 KB |
Output is correct |
18 |
Correct |
161 ms |
11980 KB |
Output is correct |
19 |
Correct |
183 ms |
13700 KB |
Output is correct |
20 |
Correct |
146 ms |
10492 KB |
Output is correct |