Table of Contents

ExplanationImplementation

Official Analysis (C++)

Explanation

To find the minimum possible solution, we can use binary search on the number of machines needed for finishing the jobs within the given deadline. With MM requests, the number of needed machines must lie in the range [1,M][1, M] as in the worst case where all the requests are given on the last day, we still have D+1D + 1 days to process these requests.

For each number of machines being tested, we can check its feasibility in linear time if the given job requests are already sorted in ascending order with respect to the request date. We iterate through each day ii from 11 to NN and add requests to the schedule in the sorted order. If there is no available machine left on a certain day ii while there are still requests not processed, we move to next day i+1i+1 and process these requests. If the day ii exceeds the delay limit for the current job being processed, i.e. the request date of the job added with the permitted delay is strictly less than the current day ii, we can stop iterating as it is not possible to use the giving number of machines to process all the jobs within the deadline. Otherwise, if we have processed all job requests, the number of machines being tested is feasible, and we also found a schedule for these jobs.

Implementation

Time Complexity: O(NlogN)\mathcal{O}(N \log N)

C++

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using std::vector;
int main() {
int n, d, m;
std::cin >> n >> d >> m;

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!