Editorial for MALD Contest 1 P3 - Scratch Cat and Infestation
Submitting an official solution before solving the problem yourself is a bannable offence.
Simulating all days is too slow because there's a maximum of days.
We can cut down the days to simulate if we skip to the day when there are Yubocats. If there are at least Yubocats, there will be at least one infection a day. The simulation days are now bounded by .
Sort the natural infection times in ascending order. The index will be the first day where there are Yubocats. Now you can simulate the remaining days.
While simulating, it is always optimal for Yubocats to manually infect cats naturally infected latest. If one cat is naturally infected tomorrow and another in a million days, it is always optimal to infect the latter cat. Keep in mind that manually infected cats become Yubocats the next day. You can simplify your implementation by using a pending variable to store the number of cats that will become a Yubocat the next day.
Complexity:
Comments