# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
619954 | gmsong | Job Scheduling (CEOI12_jobs) | C++11 | 661 ms | 20656 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int n, d, m;
vector<pair<int, int> > v;
int a[100001];
bool possible(int machines){
int day = 1;
memset(a,0,sizeof(a));
for(int i = 0; i < m; i++){
int early = v[i].first;
int late = v[i].first + d;
day = early;
while(a[day] >= machines){
day++;
}
if(day > late){
return 0;
}
a[day]++;
}
return 1;
}
int main() {
cin >> n >> d >> m;
for(int i = 1; i <= m; i++){
int val;
cin >> val;
v.push_back({val, i});
}
sort(v.begin(), v.end());
// cout << possible(11) << endl;
int lo = 1;
int hi = m;
int ans = 0;
while(lo <= hi){
int mid = (lo + hi)/2;
// cout << "mid is " << mid << endl;
if(possible(mid)){
// cout << "worked" << endl;
hi = mid - 1;
ans = mid;
}
else{
lo = mid + 1;
}
}
cout << ans << endl;
int day = 1;
vector<int> schedule[100001];
for(int i = 0; i < m; i++){
int early = v[i].first;
int late = v[i].first + d;
day = early;
while(schedule[day].size() >= ans){
day++;
}
schedule[day].push_back(v[i].second);
}
for(int i = 1; i <= n; i++){
for(int j = 0; j < schedule[i].size(); j++){
cout << schedule[i][j] << " ";
}
cout << "0" << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |