Connection Status:
Competition Arena > VoteRigging
SRM 388 · 2008-01-15 · by bmerry · Brute Force
Class Name: VoteRigging
Return Type: int
Method Name: minimumVotes
Arg Types: (vector<int>)
Problem Statement

Problem Statement

You have used your secret mind-reading device to find out how every voter will vote in the next election. Your mind-reading device also revealed to you that all the voters are prepared to change their vote if you pay them enough.

The ith element of votes is the number of people who were originally planning to vote for candidate i. Return the minimum number of votes that you must change to ensure that candidate 0 (your favorite) will have more votes than any other candidate.

Constraints

  • votes will contain between 1 and 50 elements, inclusive.
  • Each element of votes will be between 1 and 100, inclusive.
Examples
0)
{5, 7, 7}
Returns: 2

Buying one vote from each of the other two candidates leaves candidate 0 with 7 votes and the others with 6 each.

1)
{10, 10, 10, 10}
Returns: 1

You need strictly more votes than all other candidates, so you need to buy one vote.

2)
{1}
Returns: 0

If you are the only candidate, you automatically win.

3)
{5, 10, 7, 3, 8}
Returns: 4
4)
{100}
Returns: 0

Submissions are judged against all 75 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class VoteRigging with a public method int minimumVotes(vector<int> votes) · 75 test cases · 2 s / 256 MB per case

Submitting as anonymous