Editorial for BSSPC '21 J4 - James's Magical Soups
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
For the first subtask, we make the greedy observation that for each minute, if there are multiple possible soups that we can choose to drink, it is always optimal to drink the one that expires the soonest (i.e. has the minimum ). Knowing this, we can naively loop through the soups every minute, always choosing to drink the soup with the minimum out of the soups that are available to drink. It is helpful to note that the soup is only drinkable when it is between and minutes old, inclusive.
Time Complexity:
Subtask 2
For the second subtask, we can speed up our algorithm using a priority queue. First, we sort the soups in order of ascending . Each minute, we can add any newly cool-enough-to-drink soups to the priority queue, then repeatedly pop the soup with the minimum from the queue until either the queue is empty, or we find an unexpired soup to drink.
Time Complexity:
Comments