← 返回 bloomberg 的题目列表Fair Electoral Vote Apportionment
类型:online_judge
Fair Electoral Vote Apportionment
There are 50 states. State i has population population[i]. Allocate a total of E electoral votes subject to the following rules:
Every state receives at least one vote.
The remaining votes should be allocated as proportionally to population as possible.
Define fairness using the largest-remainder (Hamilton) method:
Give every state one vote first.
Let R = E - 50 be the number of remaining votes.
Compute quota[i] = population[i] / sum(population) * R.
Each state first receives floor(quota[i]) additional votes.
Allocate any unassigned votes in descending order of the fractional parts of quota[i].
Break equal fractional-part ties by smaller state index (states are indexed from 0).
Output an array of 50 integers, where element i is the final number of electoral votes allocated to state i.
Input Format
Line 1: integer E, the total number of electoral votes.
Line 2: 50 positive integers representing state populations.
Output Format
Print 50 space-separated integers representing the allocation.
Constraints
50 <= E <= 10^9
1 <= population[i] <= 10^12
The total population is positive.
Example
Input:
55
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output:
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Each state first gets one vote. The five remaining votes have equal fractional remainders for every state, so they go to states with indices 0 through 4.
Example
Input
50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1