#icpc2014springg. [icpc2014spring_g]Proportional Representation
[icpc2014spring_g]Proportional Representation
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
An election selecting the members of the parliament in JAG Kingdom was held. The only system adopted in this country is the party-list proportional representation. In this system, each citizen votes for a political party, and the number of seats a party wins will be proportional to the number of votes it receives. Since the total number of seats in the parliament is an integer, of course, it is often impossible to allocate seats exactly proportionaly. In JAG Kingdom, the following method, known as the D'Hondt method, is used to determine the number of seats for each party.
Assume that every party has an unlimited supply of candidates and the candidates of each party are ordered in some way. To the -th candidate of a party which received votes, assign the value . Then all the candidates are sorted in the decreasing order of their assigned values. The first candidates are considered to win, where is the total number of seats, and the number of seats a party win is the number of its winning candidates.
The table below shows an example with three parties. The first party received votes, the second votes, and the third votes. If the total number of seats is , the first party will win seats, the second seats, and the third seats.
When selecting winning candidates, ties are broken by lottery; any tied candidates will have a chance to win. For instance, in the example above, if then two candidates tie for the value and there are two possible outcomes:
-
The first party wins seats, the second seats, and the third seat.
-
The first party wins seat, the second seats, and the third seat.
You have just heard the results of the election on TV. Knowing the total number of valid votes and the number of seats each party won, you wonder how many votes each party received.
Given , , and (), denoting the total number of valid votes, the number of parties, and the number of seats the -th party won, respectively, your task is to determine for each party the minimum and the maximum possible number of votes it received. Note that for some cases there might be no such situation with the given , , and .
Input
The first line of the input contains two integers () and (), where is the total number of valid votes and is the number of parties. lines follow, the -th of which contains a single integer (), representing the number of seats the -th party won. You can assume that there exists with .
Output
If there is no situation with the given , , and , display the word "impossible". Otherwise, output lines, each containing two integers. The first integer and the second integer in the -th line should be the minimum and the maximum possible number of votes the -th party received, respectively.
Sample Input 1
10 2
2
1```
### Output for the Sample Input 1
```plain
5 7
3 5```
* * *
### Sample Input 2
```plain
5 6
0
2
0
2
6
0```
### Output for the Sample Input 2
```plain
0 0
1 1
0 0
1 1
3 3
0 0```
* * *
### Sample Input 3
```plain
2000 5
200
201
202
203
204```
### Output for the Sample Input 3
```plain
396 397
397 399
399 401
401 403
403 404```
* * *
### Sample Input 4
```plain
15 10
1
1
1
1
1
1
1
1
1
13```
### Output for the Sample Input 4
```plain
impossible```
* * *
### Sample Input 5
```plain
1000000000 9
12507
16653
26746
21516
29090
10215
28375
21379
18494```
### Output for the Sample Input 5
```plain
67611619 67619582
90024490 90033301
144586260 144597136
116313392 116323198
157257695 157269050
55221291 55228786
153392475 153403684
115572783 115582561
99976756 99985943```
* * *
### Source Name
[Japan Alumni Group Spring Contest 2014](http://acm-icpc.aitea.net/index.php?2013%2FPractice%2F%BD%D5%A5%B3%A5%F3%A5%C6%A5%B9%A5%C8%2F%B0%C6%C6%E2)
* * *