#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
int n, d, m;
pair<bool, vector<vi>> feas(int k, const vector<pi> &jobs) {
int jobnum = 0;
vector<vi> ans(n);
for (int i=1; i<=n; i++) {
for (int j = 0; j < k; j++) {
if (jobs[jobnum].f > i) break;
if (jobs[jobnum].f + d >= i) {
ans[i - 1].push_back(jobs[jobnum++].s);
} else {
// can't fit this job
return mp(false, ans);
}
if (jobnum == m) {
// finished all jobs
return mp(true, ans);
}
}
}
return mp(false, ans);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> d >> m;
vector<pi> jobs(m);
for (int i = 0; i < m; i++) {
int day;
cin >> day;
jobs[i] = {day, i + 1};
}
sort(all(jobs));
int lo = 1, hi = m;
vector<vi> ret;
while (lo < hi) {
int mid = (lo + hi) / 2;
pair<bool, vector<vi>> res = feas(mid, jobs);
if(res.f) {
hi = mid;
ret = res.s;
} else {
lo = mid + 1;
}
}
cout << lo << "\n";
for (int i = 0; i < n; i++) {
for (int &idx : ret[i]) {
cout << idx << " ";
}
cout << 0 << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
2960 KB |
Output is correct |
2 |
Correct |
28 ms |
2960 KB |
Output is correct |
3 |
Correct |
28 ms |
2960 KB |
Output is correct |
4 |
Correct |
28 ms |
2960 KB |
Output is correct |
5 |
Correct |
31 ms |
3032 KB |
Output is correct |
6 |
Correct |
29 ms |
2960 KB |
Output is correct |
7 |
Correct |
28 ms |
2976 KB |
Output is correct |
8 |
Correct |
29 ms |
2984 KB |
Output is correct |
9 |
Correct |
73 ms |
9636 KB |
Output is correct |
10 |
Correct |
75 ms |
9780 KB |
Output is correct |
11 |
Correct |
36 ms |
2868 KB |
Output is correct |
12 |
Correct |
78 ms |
4948 KB |
Output is correct |
13 |
Correct |
107 ms |
8612 KB |
Output is correct |
14 |
Correct |
173 ms |
10832 KB |
Output is correct |
15 |
Correct |
189 ms |
10892 KB |
Output is correct |
16 |
Correct |
249 ms |
16100 KB |
Output is correct |
17 |
Correct |
301 ms |
18704 KB |
Output is correct |
18 |
Correct |
309 ms |
23156 KB |
Output is correct |
19 |
Correct |
397 ms |
26352 KB |
Output is correct |
20 |
Correct |
295 ms |
18708 KB |
Output is correct |