Hide

Problem D
Seat Allocation

Languages da en

Consider an election where n parties run for m seats in parliament. Let vi be the number of votes cast for party i{1,,n}. To allocate the m seats to the parties, roughly proportional to their share of votes, one can use a system called D’Hondt’s method. It works like this: A quotient is calculated for each party, initially vi/1, the number of votes. The party with the largest quotient wins one seat, and its quotient is recalculated. This is repeated until all m seats is filled. The formula for the quotient is

visi+1

where si is the number of seats allocated to party i so far, initially 0 for all parties.

Input

On the first line of input: the number n of parties and m of seats, with n,m{1,,20000}, separated by a single space. On each of the following n lines, the integer vi, satisfying 1vi50000000 and v1++vnm. We also promise that the inputs are constructed so that the final seat can be uniquely determined—no tie breaking will be necessary.

Test groups

There are two tests groups. The inputs in test group 1, worth 80 of the 100 total points, satisfy the additional constraint mvi231. This may avoid some rounding issues, depending on your choice of programming language and quotient calculations.

Output

The seat distribution, one per line, in the format shown in the example. The order is the same as in the input.

Explanation of Sample Input 4

Party 1 gets the first seat because it has the most votes; its quotient is recalculated to 172. Party 2 gets the next seat because 10>172; its quotient is recalculated to 102=5. The third seat goes to Party 1, because 172>5, and the new quotient is 173. Even the final seat goes to Party 1, because 173>5. In total, Party 1 gets 3 seats and Party 2 gets 1 seat.

Sample Input 1 Sample Output 1
2 2
10
10000000
0
2
Sample Input 2 Sample Output 2
2 3
12
11
2
1
Sample Input 3 Sample Output 3
2 4
12
11
2
2
Sample Input 4 Sample Output 4
2 4
17
10
3
1
Sample Input 5 Sample Output 5
4 14
38
35
36
37
4
3
3
4
Hide

Please log in to submit a solution to this problem

Log in