CF2152A.Increase or Smash

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Increase or Smash

Geumjae has an array aa consisting of nn zeros. His goal is to transform it into a given target array using a minimum number of operations.

He can perform the following two types of operations any number of times, in any order:

  1. Increase: Choose any positive integer xx. Increase all elements of the array aa by xx. In other words, he chooses a positive integer xx, and for each ii (1in1 \le i \le n), he replaces aia_i with ai+xa_i + x.
  2. Smash: Set some elements (possibly none or all) of the array aa to 00. In other words, for each ii (1in1 \le i \le n), he either replaces aia_i with 00 or leaves it as before.

Given the final target state of the array aa, find the minimum total number of operations (both Increase and Smash) Geumjae needs to perform.

It can be shown that for any given final array, a sequence of operations always exists.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \le t \le 1000). The description of the test cases follows.

The first line contains a single integer nn (1n1001 \le n \le 100) — the number of elements in the array aa.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1001 \le a_i \le 100) — the elements of the target array aa.

Output

For each test case, output a single integer — the minimum number of operations required.

Note

Explanation of the first test case:

The target array is [1,1,3][1, 1, 3]. A possible sequence of 3 operations (which is the minimum) is:

  1. Initially, the array is [0,0,0][0, 0, 0]. After an Increase operation with x=2x = 2, the array becomes [2,2,2][2, 2, 2].
  2. Next, after a Smash operation on the first two elements, the array becomes [0,0,2][0, 0, 2].
  3. Finally, after an Increase operation with x=1x = 1, the array becomes [1,1,3][1, 1, 3].

We used 22 Increase operations and 11 Smash operation for a total of 33 operations.

Explanation of the second test case:

The target array is [100][100]. A single Increase operation with x=100x = 100 gives the target array.

Samples

3
3
1 1 3
1
100
9
9 9 3 2 4 4 8 5 3
3
1
11

在线编程 IDE

建议全屏模式获得最佳体验