CTEAMS - Editorial

PROBLEM LINKS

Practice
Contest

DIFFICULTY

EASY

EXPLANATION

Lets have a look at what happens with existing teams when a new chef enters the kitchen. Depending on his age, he is assigned to the old or to the young team. But this change might throw the size of our teams off balance. Note that a single reassignment of a chef from the young to the old team or the other way around is enough to restore the balance. To perform the first mentioned reassignement we need to find the oldest chef in the young team and move him to the old team. We can perform these operations efficiently if we maintain both teams sorted by age. For example, in C++ you can make use of a STL set to achieve time complexity O(N*log N). The same thing can be accomplished with two heaps - max heap for the young team and min heap for the old.

SETTER’S SOLUTION

Can be found here.

TESTER’S SOLUTION

Can be found here