Under construction

Still being built. Things may change

Dividing an orange

Time limit1sMemory limit1024 MB

Summary
For each wildcard rank, find the minimum and maximum number of oranges that person can get in the ranked voting game with n people and k oranges.
Level

Hard8 of 10

Topics
Game theory, Math, Recursion
Solved
No attempts yet

Problem

On a faraway planet i1c5l, a community of nn people harvested kk oranges. Now they have to divide the harvest among themselves.

The community is ruled by a democratic principle based on rank. The harvest is divided as follows. Each person gets a rank from 1 to nn. The person ranked 1 announces a decision: who gets how many oranges. Then all nn people vote "for" or "against". If at least half of the people vote "for", the decision is accepted. Otherwise the person ranked 1 is ostracized from the community, the person ranked 2 announces a decision, and the procedure repeats.

Each person wants to get as many oranges as possible for himself. Between cases with equal amounts of oranges, he prefers the one with fewer people left in the community. A person who is ostracized is considered to have received a negative amount of oranges. If several optimal solutions exist, a person can choose any of them. Each person knows that the others also look for an optimal solution guided by the same principles.

However, one member of the community has mm wildcards, and each one gives him a predefined rank. For each wildcard rank, find the minimum and maximum number of oranges he can obtain.

Input

The first line contains integers nn, kk, and mm (1≤n,k≤1091 \le n, k \le 10^9, 1≤m≤1051 \le m \le 10^5), the number of people, the number of oranges, and the number of wildcards. The second line contains mm integers a1,a2,…,ama_1, a_2, \ldots, a_m (1≤ai≤n1 \le a_i \le n), where aia_i is the rank given by the ii-th wildcard.

Output

For each aia_i, print the minimum and maximum number of oranges the wildcard owner can obtain on a separate line. Print "-1 -1" if he is ostracized.

Hint

In the first example, the person ranked 1 takes all the oranges and votes "for".

In the second example, the person ranked 1 must give the orange to the person ranked 3. If the first person takes one orange, the rest vote "against". If he gives the orange to the second person, the second also votes "against", because he knows that ostracizing the first leads to an orange for them too, but with fewer people left. Since the third person also votes "against", this option is not available to the first person.

Examples2

  1. Example 1

    Input
    2 10 2
    1 2
    
    Expected output
    10 10
    0 0
    
  2. Example 2

    Input
    3 1 2
    1 3
    
    Expected output
    0 0
    1 1