#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, d, m; cin >> n >> d >> m;
vector<int> a(m);
for (int i = 0; i < m; ++i) {
cin >> a[i]; -- a[i];
}
vector<int> ord(m); iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return a[i] < a[j];
});
vector<vector<int>> events(n);
auto check = [&](int md) {
priority_queue<array<int, 2>, vector<array<int, 2>>, greater<array<int, 2>>> pq;
for (int i = 0, j = 0; i < n; ++i) {
if (pq.size() && pq.top()[0] < i) {
return 0;
}
while (j < m && a[ord[j]] == i) {
pq.push({i + d, ord[j++]});
}
vector<int>().swap(events[i]);
int cnt = md;
while (cnt-- && pq.size()) {
events[i].push_back(pq.top()[1]);
pq.pop();
}
}
return !pq.size();
};
int l = 0, r = m, res = m;
while (l <= r) {
int md = (l + r) / 2;
if (check(md)) {
res = md;
r = md - 1;
} else {
l = md + 1;
}
}
check(res);
cout << res << "\n";
for (int i = 0; i < n; ++i) {
for (int j : events[i]) {
cout << j + 1 << " ";
}
cout << 0 << "\n";
}
return 0;
}
Compilation message
jobs.cpp: In lambda function:
jobs.cpp:40:12: error: inconsistent types 'int' and 'bool' deduced for lambda return type
40 | return !pq.size();
| ^~~~~~~~~~