CSES - Movie Festival II
Authors: Shreyas Thumathy, Benjamin Qi
Appears In
The first step is the same as that of Movie Festival; sort the movies in increasing order of end time. For each movie in order, we will assign it to one of the members to watch (or none of them).
Keep track of the time each member finishes watching all of his currently assigned movies in a sorted collection (e.g. a multiset
in C++). Initially, the collection consists of zeroes.
For each movie in order, we can assign a member to watch it if there exists an element in the sorted collection less than or equal to the start time of the movie. If there are multiple such elements, choose the greatest one (the member who finished watching his assigned movies the latest). Assign the member to watch this movie by incrementing the answer and updating the collection accordingly.
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!