Editorial for LCC ‘23 Contest 1 S5 - Spooky Children
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
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 children, then it's always best to choose the children with highest to save. We should never "waste" any feedings on any other children either.
So the general strategy is to binary search on ; to check if some particular value of is possible, we try to save each of the children with highest metabolism level. We'll simulate this process for 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 , we can check if we can save children in . Since we binary search for , this can be checked in .
Comments