Here is the problem.

USACO 2018 US Open Contest, Bronze

Problem 2. Milking Order

I have no clue what the solution is saying. Here is my solution.

I only got 3 test cases right so don’t count on my solution. I know I’m being pretty vague, but can anyone explain to me the general idea and implementation of the solution that usaco has?