Editorial for LCC ‘23 Contest 1 S5 - Spooky Children


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: Trent

Firstly, let's figure out an algorithm for feeding the children. If we want to save every single child, then it is optimal to continually feed the 3 children with lowest hunger levels. Informally, this is because we must feed them eventually anyways and feeding them earlier or later won't affect the amount of we can satiate any child by on any move. If, we fed another child instead and this one later, then it is always either just as good or better to feed this (more urgent) child before the other.

Of course, the question does not ask us to feed every child. However, if we do save X children, then it's always best to choose the X children with highest A_i to save. We should never "waste" any feedings on any other children either.

So the general strategy is to binary search on X; to check if some particular value of X is possible, we try to save each of the X children with highest metabolism level. We'll simulate this process for K days and check if it's possible by using a priority queue (or ordered set) to continually take the 3 most "urgent" children and feed them. Instead of decreasing the hunger level of each child, we can instead increment a "day counter" at the end of each day and comparing the most urgent child's value to the day counter to check if they live. Hence, for a particular value of X, we can check if we can save X children in O(K\log X). Since we binary search for X, this can be checked in O(K\log^2 N).


Comments

There are no comments at the moment.