CF1992B.Angry Monk

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

Angry Monk

To celebrate his recovery, k1o0n has baked an enormous nn metres long potato casserole.

Turns out, Noobish_Monk just can't stand potatoes, so he decided to ruin k1o0n's meal. He has cut it into kk pieces, of lengths a1,a2,,aka_1, a_2, \dots, a_k meters.

k1o0n wasn't keen on that. Luckily, everything can be fixed. In order to do that, k1o0n can do one of the following operations:

  • Pick a piece with length ai2a_i \ge 2 and divide it into two pieces with lengths 11 and ai1a_i - 1. As a result, the number of pieces will increase by 11;
  • Pick a slice aia_i and another slice with length aj=1a_j=1 (iji \ne j) and merge them into one piece with length ai+1a_i+1. As a result, the number of pieces will decrease by 11.

Help k1o0n to find the minimum number of operations he needs to do in order to merge the casserole into one piece with length nn.

For example, if n=5n=5, k=2k=2 and a=[3,2]a = [3, 2], it is optimal to do the following:

  1. Divide the piece with length 22 into two pieces with lengths 21=12-1=1 and 11, as a result a=[3,1,1]a = [3, 1, 1].
  2. Merge the piece with length 33 and the piece with length 11, as a result a=[4,1]a = [4, 1].
  3. Merge the piece with length 44 and the piece with length 11, as a result a=[5]a = [5].

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4).

Description of each test case consists of two lines. The first line contains two integers nn and kk (2n1092 \le n \le 10^9, 2k1052 \le k \le 10^5) — length of casserole and the number of pieces.

The second line contains kk integers a1,a2,,aka_1, a_2, \ldots, a_k (1ain11 \le a_i \le n - 1, umai=num a_i = n) — lengths of pieces of casserole, which Noobish_Monk has cut.

It is guaranteed that the sum of kk over all tt test cases doesn't exceed 21052 \cdot 10^5.

Output

For each test case, output the minimum number of operations K1o0n needs to restore his pie after the terror of Noobish_Monk.

Samples

4
5 3
3 1 1
5 2
3 2
11 4
2 3 1 5
16 6
1 6 1 1 1 6
2
3
9
15

在线编程 IDE

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