Question meaning: a group of individual cows only produce milk at a fixed time. Each cow needs to use a milking machine. Ask how many milking machines are needed at least to meet the needs of all cows, and output the number of the milking machine according to the order given by the cows.
First, the cows are sorted from small to large according to the start time of milk production. If the start time is the same, the cows are sorted from small to large according to the end time. Then a priority queue of priority end time is used to maintain the current milk producing cow. If the start time of the next cow is less than or equal to the end time of the current cow, a milk producing machine needs to be reused and incorporated into the queue. If it is greater than the end time of the current cow, a milking machine can be used together and the current milk producing cow can be updated.
The code is as follows: