Editorial for BSSPC '22 P7 - Exec Team Applications


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Riolku

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 M. Instead of choosing the least-bothersome member, we need to know who the Mth 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 M. That way, the largest element is always the globally Mth largest.


Comments

There are no comments at the moment.