RCV Simplification
시간 제한1초메모리 제한1024 MB
선호투표에서 각 유권자의 1순위만 주어졌을 때, 나머지 순위를 어떻게 배분해도 당선될 수 없는 후보를 찾아 사전순으로 출력한다.
문제
The following is from Ballotpedia [ https://ballotpedia.org/Ranked-choice_voting_(RCV) ]:
Broadly speaking, the ranked-choice voting process unfolds as follows for single-winner elections:
- Voters rank the candidates for a given office by preference on their ballots.
- If a candidate wins an outright majority of first-preference votes (i.e., 50 percent plus one), he or she will be declared the winner.
- If, on the other hand, no candidates win an outright majority of first-preference votes, the candidate with the fewest first-preference votes is eliminated.
- All first-preference votes for the failed candidate are eliminated, lifting the secondpreference choices indicated on those ballots.
- A new tally is conducted to determine whether any candidate has won an outright majority of the adjusted voters.
- The process is repeated until a candidate wins a majority of votes cast.
Example: Assume that there are four candidates in an election. The table below presents the raw first-preference vote totals for each candidate:
In the above scenario, no candidate won an outright majority of first-preference votes. As a result, the candidate (Candidate D) with the smallest number of first-preference votes is eliminated. The ballots that listed candidate D as the first preference are adjusted, raising their second-preference candidates. Assume that, of the 75 first-preference votes for Candidate D, 50 listed Candidate A as their second preference and 25 listed Candidate B. The adjusted vote totals would be as follows:
On the second tally, Candidate A secured 51.22 percent of the vote, thereby winning the election.
Note: If several candidates are tied for the fewest first-preference votes, all such candidates are eliminated. So, candidates not eliminated must have at least one more first-preference vote than those eliminated.
We have received information on the percentage for the first-preference for each candidate, but we don’t know how the candidates are listed as the second preference, third preference, etc. Help write a program to remove candidates that cannot possibly win. More specifically, given the current votes for a set of candidates, find the set of candidates that cannot possibly win.
입력
The first input line contains a single integer, N (1 ≤ N ≤ 100,000), representing the number of votes. Each of the following N input lines contains a candidate name receiving the first-place vote from that voter. Each candidate name is 1-25 letters (lowercase and uppercase), starting in column one.
출력
On the first output line, print a single positive integer, C, the number of candidates that cannot win. Each of the remaining C output lines should contain a candidate name that cannot win. The candidate names should be printed in lexicographical order (increasing order).