Editorial for WC '16 Contest 2 J1 - The Perfect Mate


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.

We'll need to iterate over all N warriors, inputting their information and keeping track of the best mate seen so far. We'll need to remember both this optimal mate's name (so that it can be outputted at the end), and his number of victories (so that we can determine if a superior mate is found). For convenience, we can initialize his name as None and victory count as -1. In this way, any suitable mate will replace him, and if no suitable mates are found, we'll proceed to output None.

When we consider each warrior, we should simply ignore them if they've lost more than 0 battles. Otherwise, they should become the new optimal mate if they've won strictly more battles than the previous mate has. If they've only won an equal number of battles, the previous optimal mate should be retained, as they appeared earlier in the list.


Comments

There are no comments at the moment.