#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> requests;
int n, d, m;
pair<vector<vector<int>>, bool> valid(int num_machines){
vector<vector<int>> schedule(n);
int reqNum = 0;
for(int day = 0; day < n; day++){
for(int i=0; i < num_machines; i++){
if(requests[reqNum].first > day + 1){
break;
}
if(requests[reqNum].first + d < day + 1) return make_pair(schedule, false);
schedule[day].push_back(requests[reqNum++].second);
if(reqNum == m) return make_pair(schedule, true);
}
}
return make_pair(schedule, false);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> d >> m;
requests.resize(m);
for(int i=0; i<m; i++){
cin >> requests[i].first;
requests[i].second = i;
}
sort(requests.begin(), requests.end());
vector<vector<int>> schedule;
int lo = 1, hi = m;
while(lo < hi){
int mid = lo + (hi - lo) / 2;
pair<vector<vector<int>>, bool> res = valid(mid);
if(res.second){
hi = mid;
schedule = res.first;
} else {
lo = mid + 1;
}
}
cout << hi << '\n';
for(auto day: schedule){
for(int job: day){
cout << job + 1 << ' ';
}
cout << "0\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |