Submission #680287

#TimeUsernameProblemLanguageResultExecution timeMemory
680287SriniVJob Scheduling (CEOI12_jobs)C++14
100 / 100
368 ms17140 KiB
#include <bits/stdc++.h> using namespace std; int n , d , m; vector<pair < int , int > > jobs; bool valid(int machines){ int day = 1; int count = 0; for(auto job : jobs){ if(job.first>day){ count = 0; day = job.first; } if(count==machines){ count = 0; day++; } if(day - job.first > d){ return false; } count++; } return true; } int main(){ cin >> n >> d >> m; jobs.resize(m); for(int i = 0;i<m;i++){ cin >> jobs[i].first; jobs[i].second = i+1; } sort(jobs.begin() , jobs.end()); int left = 1 , right = m; int answer = -1; while(left<=right){ int middle = left + (right - left)/2; if(valid(middle)){ answer = middle; right = middle - 1; } else { left = middle + 1; } } cout << answer<<"\n"; int count = 0; for(int day = 1;day<=n;day++){ for(int i = 0;i<answer;i++){ if(jobs[count].first>day||count==m)break; cout << jobs[count++].second<<" "; } cout << 0 << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...