#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int n, d, m;
priority_queue<int, vector<int>, greater<>> reqs;
priority_queue<int, vector<int>, greater<>> reqsCopy;
priority_queue<int, vector<int>, greater<>> pq;
map<int, queue<int>> locs;
bool test(int x){
for(int day=reqs.top(); day<n; day++){
if (empty(pq) and empty(reqs)) break;
while (!empty(reqs) and reqs.top() <= day) {
pq.push(reqs.top() + d);
reqs.pop();
}
for(int i=0; i<x; i++){
// Complete the x tasks that are due soonest. If any are overdue, then return false
if (day > pq.top()) return false;
else pq.pop();
if (empty(pq)) break;
}
}
return (empty(pq));
}
int main() {
cin >> n >> d >> m;
int x;
for(int i=1; i<=n; i++){
locs.insert({i, {}});
}
for(int i=0; i<m; i++){
cin >> x;
reqs.push(x);
locs[x].push(i+1);
}
int lo = 1;
int hi = INT_MAX;
int mid;
reqsCopy = priority_queue<int, vector<int>, greater<>> (reqs);
while(lo < hi){
reqs = priority_queue<int, vector<int>, greater<>> (reqsCopy);
pq = {};
mid = lo + (hi-lo)/2;
if (test(mid)){
hi = mid;
}
else lo = mid+1;
}
cout << lo << endl;
// Print out optimal movements
reqs = priority_queue<int, vector<int>, greater<>> (reqsCopy);
pq = {};
string dayOut;
for(int day=1; day<=n; day++){
dayOut = "";
while (!empty(reqs) and reqs.top() <= day) {
pq.push(reqs.top() + d);
reqs.pop();
}
for(int i=0; i<lo; i++){
if (empty(pq)) break;
else{
int goodIdx = locs[pq.top()-d].front();
locs[pq.top()-d].pop();
dayOut += to_string(goodIdx) + " ";
pq.pop();
}
}
dayOut += "0";
cout << dayOut << endl;
}
return 0;
}
Compilation message
jobs.cpp: In function 'bool test(int)':
jobs.cpp:15:13: error: 'empty' was not declared in this scope; did you mean 'mempcpy'?
15 | if (empty(pq) and empty(reqs)) break;
| ^~~~~
| mempcpy
jobs.cpp:16:17: error: 'empty' was not declared in this scope; did you mean 'mempcpy'?
16 | while (!empty(reqs) and reqs.top() <= day) {
| ^~~~~
| mempcpy
jobs.cpp:24:17: error: 'empty' was not declared in this scope; did you mean 'mempcpy'?
24 | if (empty(pq)) break;
| ^~~~~
| mempcpy
jobs.cpp:27:13: error: 'empty' was not declared in this scope; did you mean 'mempcpy'?
27 | return (empty(pq));
| ^~~~~
| mempcpy
jobs.cpp: In function 'int main()':
jobs.cpp:62:17: error: 'empty' was not declared in this scope; did you mean 'mempcpy'?
62 | while (!empty(reqs) and reqs.top() <= day) {
| ^~~~~
| mempcpy
jobs.cpp:67:17: error: 'empty' was not declared in this scope; did you mean 'mempcpy'?
67 | if (empty(pq)) break;
| ^~~~~
| mempcpy