CF1916C.Training Before the Olympiad

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Masha and Olya have an important team olympiad coming up soon. In honor of this, Masha, for warm-up, suggested playing a game with Olya:

There is an array aa of size nn . Masha goes first, and the players take turns. Each move is described by the following sequence of actions:

\bullet If the size of the array is 11 , the game ends.

\bullet The player who is currently playing chooses two different indices ii , jj ( 1i,ja1 \le i, j \le |a| ), and performs the following operation — removes aia_i and aja_j from the array and adds to the array a number equal to ai+aj22\lfloor \frac{a_i + a_j}{2} \rfloor \cdot 2 . In other words, first divides the sum of the numbers aia_i , aja_j by 22 rounding down, and then multiplies the result by 22 .

Masha aims to maximize the final number, while Olya aims to minimize it.

Masha and Olya decided to play on each non-empty prefix of the initial array aa , and asked for your help.

For each k=1,2,,nk = 1, 2, \ldots, n , answer the following question. Let only the first kk elements of the array aa be present in the game, with indices 1,2,,k1, 2, \ldots, k respectively. What number will remain at the end with optimal play by both players?

输入格式

The first line contains an integer tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases.

The first line of each test case contains a single integer nn ( 1n1051 \le n \le 10^5 ) — the size of the array.

The second line contains nn integers a1,a2,,ana_1,a_2, \ldots,a_n ( 1ai1091 \leq a_i \leq 10^9 ) — the array on which Masha and Olya play.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5 .

输出格式

For each test case, output nn integers. The kk -th of these numbers should be equal to the number that will remain at the end with optimal play by both players, on the array consisting of the first kk elements of the array aa .

输入输出样例

  • 输入#1

    4
    1
    31
    6
    6 3 7 2 5 4
    3
    3 10 11
    5
    7 13 11 19 1

    输出#1

    31 
    6 8 16 18 22 26 
    3 12 24 
    7 20 30 48 50

说明/提示

In the third test case, for a prefix of length 11 , the answer is 33 . For a prefix of length 22 , Masha has only one move, so the answer is 1212 . For a prefix of length 33 , Masha has three possible moves: she chooses 33 and 1010 , then the final number is 2222 , 33 and 1111 , then the final number is 2424 , 1010 and 1111 , then the final number is 2222 , so Masha will choose 33 and 1111 and get 2424 .

首页