ElectionFraudDiv1
SRM 544 · 2011-11-22 · by pieguy
Problem Statement
In a normal election, one expects the percentages received by each of the candidates to sum to exactly 100 percent. There are two ways this might not be the case: if the election is fraudulent, or if the reported percentages are rounded.
For example, in an election with 3 voters and 3 candidates, if each voter chooses a different candidate the final percentages would be reported as 33, 33, 33, which only sum to 99. Conversely, in an election with 7 voters and 3 candidates, if the candidates receive 2, 2, and 3 votes, respectively, the final percentages would be reported as 29, 29, and 43, which sum to 101.
The ministry of voting wants you to help them determine if an election was run fairly or not. You'll be given a
Notes
- You may assume that whenever the election may be legitimate, the smallest possible number of voters will fit into a int.
Constraints
- percentages will contain between 1 and 50 elements, inclusive.
- Each element of percentages will be between 0 and 100, inclusive.
{33, 33, 33}
Returns: 3
The first example from the problem statement.
{29, 29, 43}
Returns: 7
The second example from the problem statement.
{12, 12, 12, 12, 12, 12, 12, 12}
Returns: -1
These results are impossible.
{13, 13, 13, 13, 13, 13, 13, 13}
Returns: 8
{0, 1, 100}
Returns: 200
The only possibility is that the candidates received 0, 1, and 199 votes, respectively.
Submissions are judged against all 160 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ElectionFraudDiv1 with a public method int MinimumVoters(vector<int> percentages) · 160 test cases · 2 s / 256 MB per case