CF BUDDY
← Problems·

1979C · Earning on Bets

1200 · binary search, combinatorics, constructive algorithms

Problem: You have been offered to play a game. In this game, there are nn possible outcomes, and for each of them, you must bet a certain integer amount of coins. In the event that the ii-th outcome turns out to be winning, you will receive back the amount of coins equal to your bet on that outcome, multiplied by kik_i. Note that exactly one of the nn outcomes will be winning.

Your task is to determine how to distribute the coins in such a way that you will come out ahead in the event of any winning outcome. More formally, the total amount of coins you bet on all outcomes must be strictly less than the number of coins received back for each possible winning outcome.

Input Format: Each test consists of multiple test cases. The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n501 \le n \le 50) — the number of outcomes.

The second line of each test case contains nn integers k1,k2,,knk_1,k_2,\ldots,k_n (2ki202 \le k_i \le 20) — the multiplier for the amount of coins if the ii-th outcome turns out to be winning.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output 1-1 if there is no way to distribute the coins as required. Otherwise, output nn integers x1,x2,,xnx_1, x_2,\ldots, x_n (1xi1091 \le x_i \le 10^{9}) — your bets on the outcomes.

It can be shown that if a solution exists, there is always a solution that satisfies these constraints.

If there are multiple suitable solutions, output any of them.

Note: In the first test case, the coins can be distributed as follows: 2727 coins on the first outcome, 4141 coins on the second outcome, 1212 coins on the third outcome. Then the total amount of coins bet on all outcomes is 27+41+12=8027 + 41 + 12 = 80 coins. If the first outcome turns out to be winning, you will receive back 327=813 \cdot 27 = 81 coins, if the second outcome turns out to be winning, you will receive back 241=822 \cdot 41 = 82 coins, if the third outcome turns out to be winning, you will receive back 712=847 \cdot 12 = 84 coins. All these values are strictly greater than 8080.

In the second test case, one way is to bet one coin on each of the outcomes.

Sample Cases

Case 1

Input

6
3
3 2 7
2
3 3
5
5 5 5 5 5
6
7 9 3 17 9 13
3
6 3 2
5
9 4 6 8 3

Output

27 41 12 
1 1 
-1
1989 1547 4641 819 1547 1071 
-1
8 18 12 9 24

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback