Codeforces Round 1014 (Div. 2)
C
Asuna and the Mosquitoes
Codeforces
1200
原题
← BD →
翻译中…

For her birthday, each of Asuna's $n$ admirers gifted her a tower. The height of the tower from the $i$-th admirer is equal to $a_i$.

翻译中…

Asuna evaluates the beauty of the received gifts as $\max(a_1, a_2, \ldots, a_n)$. She can perform the following operation an arbitrary number of times (possibly, zero).

翻译中…
  • Take such $1 \le i \neq j \le n$ that $a_i + a_j$ is odd and $a_i \gt 0$, then decrease $a_i$ by $1$ and increase $a_j$ by $1$.
翻译中…

It is easy to see that the heights of the towers remain non-negative during the operations.

翻译中…

Help Asuna find the maximum possible beauty of the gifts after any number of operations!

翻译中…

Input

翻译中…

Each test consists of several test cases. The first line of the input data contains one integer $t$ ($1 \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 $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the number of admirers of Asuna.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n \ (1 \le a_i \le 10^9)$ — the heights of the towers.

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer: the maximum value of the beauty of the gifts that Asuna can achieve.

翻译中…

Note

翻译中…

In the first test case, no pair of towers satisfies the required condition for applying the operation, so no operations can be performed. In this case, the answer is $\max(5, \ 3, \ 9) = 9$.

翻译中…

In the second test case, the operation with $i = 2$ and $j = 1$ can be applied twice. After that, the array becomes: $a \ = \ [5, \ 0]$. Thus, the answer is 5.

翻译中…

In the third test case, the following sequence of operations can be applied:

翻译中…
  1. Operation with $i=1$ and $j=2$.$[1, \ 2, \ 2, \ 1] \quad \rightarrow \quad [0, \ 3, \ 2, \ 1]$
  2. Operation with $i=3$ and $j=2$.$[0, \ 3, \ 2, \ 1] \quad \rightarrow \quad [0, \ 4, \ 1, \ 1]$
  3. Operation with $i=3$ and $j=2$.$[0, \ 4, \ 1, \ 1] \quad \rightarrow \quad [0, \ 5, \ 0, \ 1]$
翻译中…

$\max(0, \ 5, \ 0, \ 1) \ = \ 5$.

翻译中…

Therefore, the answer is 5.

翻译中…

样例

Input #1
4
3
5 3 9
2
3 2
4
1 2 2 1
5
5 4 3 2 9
Output #1
9
5
5
21
InputCopy OutputCopy
题目信息
题号
2092C
时间限制
2 s
内存限制
256 MB
标签
构造
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。