Monkey Country

View as PDF

Submit solution

Points: 10
Time limit: 3.0s
Memory limit: 512M

Author:
Problem type

Victor lives in a monkey country where every day, out of the K monkeys who have money, the top \left\lfloor\dfrac{K \cdot P}{Q}\right\rfloor of monkeys earn one dollar while everyone else loses one dollar. When a monkey runs out of money, he goes bankrupt and loses his citizenship too is no longer one of the K monkeys with money. At first, there are N monkeys and the i^{th} monkey has a_i dollars. Each monkey has a distinct number of dollars to begin with. Victor would like to know how many days there are until each monkey runs out of money.

Input Specification

The first line contains integers N, P, and Q (1 \le N, P, Q \le 10^7, P < Q), the number of monkeys in the country and the special numbers P and Q.

The next line will have a list a of N integers, (1 \le a_i \le 10^9), the i^{th} of which is how many dollars the i^{th} monkey has. No two monkeys have the same amount of money (a_i \neq a_j if i \neq j). The amount of money of the monkeys are sorted in increasing order.

Output Specification

In one line, print N integers, the i^{th} of which is how many days there are until the i^{th} monkey runs out of money modulo 10^9+7.

Sample Input 1

5 1 2
1 2 3 4 5

Sample Output 1

1 2 3 8 21

Sample Input 2

2 1 2
999999999 1000000000

Sample Output 2

999999999 999999984

Explanation for Sample 1

At the start, the money count is 1 2 3 4 5.

On day 1, the top \left\lfloor\dfrac{5 \cdot 1}{2}\right\rfloor = 2 monkeys gain money, and everyone else loses money. Thus, the new money count becomes 0 1 2 5 6. Here, monkey 1 goes bankrupt on day 1.

The rest of the days are:

0 0 1 6 7 monkey 2 goes bankrupt on day 2.

0 0 0 5 8 monkey 3 goes bankrupt on day 3.

0 0 0 4 9

0 0 0 3 10

0 0 0 2 11

0 0 0 1 12

0 0 0 0 13 monkey 4 goes bankrupt on day 8.

0 0 0 0 12

0 0 0 0 1

0 0 0 0 0 The monkey game finally ends when monkey 5 goes bankrupt on day 21.


Comments


  • 0
    Badmode  commented on Jan. 12, 2021, 12:42 a.m. edited

    Is this problem impossible to do with python 3 due to lack of time?


    • 1
      wleung_bvg  commented on Jan. 12, 2021, 2:43 a.m.

      Yes, due to the testers having a lack of time, this problem is not solvable in Python 3.

      In all seriousness, there is currently an AC using PyPy2. Perhaps PyPy3 will pass?


      • -1
        Badmode  commented on Jan. 12, 2021, 3:14 a.m. edited

        Okay, thanks for the clarification!


      • 5
        crackersamdjam  commented on Jan. 12, 2021, 3:05 a.m. edit 2

        due to the testers having a lack of time

        no u


  • 3
    ross_cleary  commented on Jan. 11, 2021, 10:31 p.m.

    Try to avoid using doubles and the floor or ceil function for this problem.


    • 0
      Badmode  commented on Jan. 12, 2021, 3:35 a.m.

      Including floor division?


      • 1
        ross_cleary  commented on Jan. 12, 2021, 11:37 p.m.

        Integer division is fine, I think issues only arise when a sub answer to an operation is stored as a double and then the floor function is used. For example storing P divided by Q as a double and then multiplying by K and flooring this value caused an error in my code. Doing by K * P and then integer division to divide by Q will not result in errors.