제출 #1134531

#제출 시각아이디문제언어결과실행 시간메모리
1134531amin5555Job Scheduling (CEOI12_jobs)C++20
95 / 100
177 ms20076 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> requests; vector<vector<int>> schedule; int n, d, m; void buildSchedule(int machines){ int day = 0; for(int i=0; i<m; i++){ schedule[day].push_back(requests[i].second); if(!((i+1) % machines)){ day++; } } } bool valid(int num_machines){ int days = 0; int cur = 0; int time = requests[0].first; for(auto req: requests){ if(time > req.first + d){ return 0; } if(cur + 1 > num_machines){ days++; time++; cur = 0; } cur++; } if(cur) days++; return days <= n; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> d >> m; schedule.resize(n); requests.resize(m); for(int i=0; i<m; i++){ cin >> requests[i].first; requests[i].second = i; } sort(requests.begin(), requests.end()); int lo = 1, hi = m; while(lo < hi){ int mid = lo + (hi - lo) / 2; if(valid(mid)){ hi = mid; } else { lo = mid + 1; } } buildSchedule(hi); cout << hi << '\n'; for(auto day: schedule){ for(int job: day){ cout << job + 1 << ' '; } cout << "0\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...