Editorial for BSSPC '22 P7 - Exec Team Applications
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
To make our calculations easier, let's consider making a team with a given member, and without loss of generality, let's suppose that this member is the least amiable.
This means that among the applicants who are more amiable than the current member, we should choose the least bothersome one.
To implement this efficiently, sort the applicants in non-increasing order of amiability. Then, consider each member in turn (except the first: since it can never be the least amiable member on a team), and keep track of the running minimum bothersome among all members.
When calculating, make sure to take the maximum of the least-bothersome member, and the current member.
Subtask 2
We will extend the previous solution to arbitrary . Instead of choosing the least-bothersome member, we need to know who the th least bothersome member is.
To do this, use a max heap. At each step we add an item to the heap, and then we remove the largest element (this is a member we don't want on our team). That is, at each step, our heap has size . That way, the largest element is always the globally th largest.
Comments