Editorial for COI '07 #1 Glasnici
Submitting an official solution before solving the problem yourself is a bannable offence.
Let us first find an algorithm that, for a given time (in seconds), checks if all messengers can get the news in the given time.
We will first show that there exists an optimal sequence of moving and shouting in which all shouting is done at the very end (after seconds). Each sequence of moving and shouting can be modified so that messenger , after he would shout the news to messenger , continues following his movement exactly. That way, all shouting can be done at the end as well.
The algorithm to check if the news can spread in seconds now becomes simple.
The first messenger runs distance units towards the second village.
The second messenger knows exactly which space interval he must be in after seconds to hear the news, and he always tries to go as far as possible from the first village.
The process continues for all messengers.
If, for any messenger, there is no way for him to be in the range of hearing his predecessor, then seconds is not enough time to spread the news.
The output is found by binary searching over .
Comments