Editorial for JDCC '15 Contest 1 P2 - Programming Elections


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.

Author: aurpine

We have to find the maximum of two sets. We just go through the list and store the current highest of both genders. We need four variables, the name and number of votes of the so-far-best boy and girl candidates. If the number of votes of the current candidate exceeds the current winning candidate of that gender, then override both the number of votes and the name. After going through all the candidates, print the two winning candidates.

Time Complexity: \(\mathcal{O}(N)\), where \(N\) is the number of candidates.


Comments

There are no comments at the moment.