USACO Training: Job Processing
It's about time I finished section 4.2 of USACO training...
USACO Training: Job Processing
We can compute the first variable of output by attempting to greedily assign the tasks to the type-A machines. This is completed by keeping track of both
- how much time an machine spends on finishing an arbitrary task AND
- how much time the machine ALREADY SPENT on finishing assigned TASKS.
The first comes from input; the second is initially zero and gradually increases.
We wish to minimize the time it takes to finish task N. The time it will take to finish any task i is the minimal possible value of m.1 + m.2 where m is any machine. Once the machine m is selected such that this value is minimized, increase the m.2 value of this machine by m.1. We repeat this process for all i from 1 to N. Notice that the answer is not dependent on what i is, but only on the m.1 and m.2 values.
Assume we store these minimum values in an array, T[1] to T[N]. Clearly the first answer is T[N]. Now, we observe that T[1] to T[N] is always nondecreasing, i.e. for arbitrary T[i], T[i] <= T[i+1].
Proof: Suppose otherwise, that T[i+1] < T[i]. Hence T[i+1] "found" a minimum m.1 + m.2 that was smaller than what T[i] "found". Since this value exists, then T[i] would have found this value instead, leading to a contradiction.
Now, for the B machines, let's start from N and go down to 1 instead, finding the minimum m.1 + m.2 for the B machines. Store the minimums in an array U[1] to U[N]. If the B machines were independent from the A machines, then U[1] would be the amount of time the B machines took. Notice that for the same reason T[1] to T[N] is always nondecreasing, U[N] to U[1] is always nondecreasing, or equivalently, U[1] to U[N] is always nonincreasing.
The maximum value of T[i] + U[i] will be the answer, since this virtually means "all the time B spends on task i plus all the time B spends waiting for task i."
By the greedy load balancing problem (my last post), the value max(T[i]+U[i]) is minimized this way, hence, this value is optimal.
And now we have the two answers!
Comments
Post a Comment