XHXMMMl31UhOFF#:).^

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Statement

To celebrate his recovery, k1o0n has baked an enormous n n 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 k k pieces, of lengths a1,a2,,ak a_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 ai2 a_i \ge 2 and divide it into two pieces with lengths 1 1 and ai1 a_i - 1 . As a result, the number of pieces will increase by 1 1 ;
  • Pick a slice ai a_i and another slice with length aj=1 a_j=1 ( ij i \ne j ) and merge them into one piece with length ai+1 a_i+1 . As a result, the number of pieces will decrease by 1 1 .

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

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

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

Format

Input

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

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

The second line contains k k integers a1,a2,,ak a_1, a_2, \ldots, a_k ( 1ain1 1 \le a_i \le n - 1 , ai=n \sum a_i = n ) — lengths of pieces of casserole, which Noobish_Monk has cut.

It is guaranteed that the sum of k k over all t t test cases doesn't exceed 2105 2 \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.

Sample

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

ShanghaiTech ACM 炸鱼杯

未参加
状态
已结束
规则
OI
题目
46
开始于
2024-12-10 23:00
结束于
2024-12-15 13:00
持续时间
110 小时
主持人
参赛人数
112