Proportional Representation
Time limit5sMemory limit128 MB
Given total votes and seats each party won under the D'Hondt rule, find the smallest and largest vote count each party could have received.
- Level
Medium7 of 10
- Topics
- Binary search, Math
- Solved
- No attempts yet
Problem
JAG Kingdom elected the members of its parliament. The country uses only party-list proportional representation: each citizen votes for one party, and the number of seats a party wins is proportional to the number of votes it receives. The parliament has an integer number of seats, so an exactly proportional split is usually impossible. The kingdom splits the seats with the D'Hondt method.
Every party has an unlimited supply of candidates, and the candidates of a party are ordered. The -th candidate of a party that received votes gets the value . All candidates are sorted by value in decreasing order, and the first candidates win, where is the total number of seats. The number of seats a party wins is the number of its winning candidates.
Take three parties with , and votes as an example. With seats the first party wins seats, the second wins seats, and the third wins seats.
Ties are broken by lottery, so every tied candidate has a chance to win. In the same example with , two candidates tie at the value , and both of the following outcomes are possible.
- The first party wins seats, the second wins seats, and the third wins seat.
- The first party wins seat, the second wins seats, and the third wins seat.
You have just heard the results of the election on TV. You know the total number of valid votes and the number of seats each party won, and you wonder how many votes each party received.
You are given the total number of valid votes , the number of parties , and the number of seats that party won. For each party, determine the minimum and the maximum number of votes it could have received. For some inputs no vote count produces the given seats at all.
Input
The first line contains two integers () and (), the total number of valid votes and the number of parties. Each of the next lines contains one integer (), the number of seats party won. At least one is not zero.
Output
If no vote count produces the given , and , print impossible. Otherwise print lines. The -th line contains two integers, the minimum and the maximum number of votes party could have received.