CF1661C.Water the Trees

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn trees in a park, numbered from 11 to nn . The initial height of the ii -th tree is hih_i .

You want to water these trees, so they all grow to the same height.

The watering process goes as follows. You start watering trees at day 11 . During the jj -th day you can:

  • Choose a tree and water it. If the day is odd (e.g. 1,3,5,7,1, 3, 5, 7, \dots ), then the height of the tree increases by 11 . If the day is even (e.g. 2,4,6,8,2, 4, 6, 8, \dots ), then the height of the tree increases by 22 .
  • Or skip a day without watering any tree.

Note that you can't water more than one tree in a day.

Your task is to determine the minimum number of days required to water the trees so they grow to the same height.

You have to answer tt independent test cases.

输入格式

The first line of the input contains one integer tt ( 1t21041 \le t \le 2 \cdot 10^4 ) — the number of test cases.

The first line of the test case contains one integer nn ( 1n31051 \le n \le 3 \cdot 10^5 ) — the number of trees.

The second line of the test case contains nn integers h1,h2,,hnh_1, h_2, \ldots, h_n ( 1hi1091 \le h_i \le 10^9 ), where hih_i is the height of the ii -th tree.

It is guaranteed that the sum of nn over all test cases does not exceed 31053 \cdot 10^5 ( n3105\sum n \le 3 \cdot 10^5 ).

输出格式

For each test case, print one integer — the minimum number of days required to water the trees, so they grow to the same height.

输入输出样例

  • 输入#1

    3
    3
    1 2 4
    5
    4 4 3 5 5
    7
    2 5 4 8 3 7 4

    输出#1

    4
    3
    16

说明/提示

Consider the first test case of the example. The initial state of the trees is [1,2,4][1, 2, 4] .

  1. During the first day, let's water the first tree, so the sequence of heights becomes [2,2,4][2, 2, 4] ;
  2. during the second day, let's water the second tree, so the sequence of heights becomes [2,4,4][2, 4, 4] ;
  3. let's skip the third day;
  4. during the fourth day, let's water the first tree, so the sequence of heights becomes [4,4,4][4, 4, 4] .

Thus, the answer is 44 .

首页