Proportional Representation
Time limit1sMemory limit128 MB
Given partial vote counts, compute for every party the maximum and minimum seats it could receive under D'Hondt allocation with a 5% threshold, over all possible distributions of remaining votes.
- Level
Hard8 of 10
- Topics
- Greedy, Binary search, Simulation, Math
- Solved
- No attempts yet
Problem
Today is election day for members of the National Assembly.
A total of V people voted, and each voter chose one of N parties. Exactly M seats will be assigned.
Seats are assigned by the D'Hondt method with a 5% threshold. The parties are numbered from 1 to N, and their final vote counts are V_1, V_2, ..., V_N. The assignment works as follows.
- A party that receives fewer than 5% of the total votes
Vis removed from seat allocation. - Initially, every party has 0 seats.
- For each remaining party
P, computeQ_P = V_P / (S_P + 1), whereS_Pis the number of seats already assigned to partyP. - The party with the largest
Q_Preceives one seat. If several parties are tied, the party with the smallest number receives the seat. - Repeat steps 3 and 4 until all seats have been assigned.
The vote count is still in progress. You know how many votes each party has received so far, but the destinations of the uncounted votes are unknown.
Given the current partial results, compute the maximum and minimum number of seats each party can end up with.
Input
The first line contains the total number of votes V, the number of parties N, and the number of seats M. (1 <= V <= 10,000,000, 1 <= N <= 100, 1 <= M <= 200)
The second line contains the number of votes currently received by each party, in party-number order. Their sum does not exceed V.
Output
On the first line, print the maximum possible number of seats for each party in party-number order.
On the second line, print the minimum possible number of seats for each party in party-number order.
Hint
In the first sample test, 14 votes have been counted and 6 votes remain. Suppose the remaining votes add 2, 0, 1, 3 votes to parties 1 through 4. The final vote counts become 6, 3, 7, 4, so every party passes the threshold.
The seats are then assigned to parties 3, 1, 4, 3, and 1, giving final seat counts 2, 0, 2, 1. Therefore, it is possible for party 2 to receive no seats.