Codeforces Round 1040 (Div. 2)
A
Submission is All You Need
Codeforces
800
原题
←B →
翻译中…

For a multiset $T$ consisting of non-negative integers, we define:

翻译中…
  • $\text{sum}(T)$ is the sum of all elements in $T$. For example, if $T = \{0,1, 1, 3\}$, then $\text{sum}(T)= 0+1+1+3=5$.
  • $\text{mex}(T)$ is the smallest non-negative integer not in $T$. For example, if $T = \{0,1, 1, 3\}$, then $\text{mex}(T) = 2$ because $2$ is the smallest non-negative integer not present in $T$.
翻译中…

You are given a multiset $S$ of size $n$ consisting of non-negative integers. At first, your score is $0$. You can perform the following operations any number of times in any order (possibly zero):

翻译中…
  • Select a subset $S' \subseteq S$ (i.e., $S'$ contains some of the elements currently in $S$), add $\text{sum}(S')$ to your score, and then remove $S'$ from $S$.
  • Select a subset $S' \subseteq S$, add $\text{mex}(S')$ to your score, and then remove $S'$ from $S$.
翻译中…

Find the maximum possible score that can be obtained.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 50$).

翻译中…

The second line of each test case contains $n$ integers $S_1, S_2, \ldots, S_n$ ($0 \le S_i \le 50$).

翻译中…

Output

翻译中…

For each test case, print a single integer — the maximum possible score that can be obtained.

翻译中…

Note

翻译中…

In the first test case, a possible optimal strategy is as follows:

翻译中…
  • Select $S'=\{0,1\}$, add $\text{mex}(S')=\text{mex}(\{0,1\})=2$ to your score, and then remove $S'$ from $S$. Currently, your score is $2$ and $S=\{1\}$.
  • Select $S'=\{1\}$, add $\text{sum}(S')=\text{sum}(\{1\})=1$ to your score, and then remove $S'$ from $S$. Currently, your score is $3$ and $S=\varnothing$.
翻译中…

After that, you cannot do any further operations. It can be proven that $3$ is the maximum possible score that can be obtained.

翻译中…

样例

Input #1
2
3
0 1 1
3
1 2 3
Output #1
3
6
InputCopy OutputCopy
题目信息
题号
2130A
时间限制
1 s
内存限制
256 MB
标签
贪心
数学

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