Election
Time limit1sMemory limit128 MB
Simulate instant-runoff voting over at most 5 candidates and 20 preference groups, eliminating the lowest scorer each round.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation, Array
- Solved
- No attempts yet
Problem
Given the voting preferences of a population of people, determine the winner of an election among candidates numbered . The people are partitioned into "groups," where all members of a group share the same voting preferences. Each group's preferences are given by listing the candidates from most preferred to least preferred. The result is determined by an instant-runoff voting procedure.
In this method, the current first choices of the people are counted, and the candidate with the fewest votes is eliminated. If several candidates tie for the fewest votes, the highest-numbered among them is eliminated. The eliminated candidate is then removed from every person's preference list, and again the candidate with the fewest votes is eliminated. This repeats until only one candidate remains, who is the winner.
Input
The input contains multiple test cases. Each test case begins with a line containing two integers and (, ). The next lines each have the form , where and is a permutation of . Here is the number of people in the -th group, and orders the candidates from most to least preferred for that group. The end of input is marked by a test case with , which should not be processed.
Output
For each test case, print the winner of the election on its own line.