CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
C
Virus
Codeforces
1200
原题
← BD →
翻译中…

There are $n$ houses numbered from $1$ to $n$ on a circle. For each $1 \leq i \leq n - 1$, house $i$ and house $i + 1$ are neighbours; additionally, house $n$ and house $1$ are also neighbours.

翻译中…

Initially, $m$ of these $n$ houses are infected by a deadly virus. Each morning, Cirno can choose a house which is uninfected and protect the house from being infected permanently.

翻译中…

Every day, the following things happen in order:

翻译中…
  • Cirno chooses an uninfected house, and protect it permanently.
  • All uninfected, unprotected houses which have at least one infected neighbor become infected.
翻译中…

Cirno wants to stop the virus from spreading. Find the minimum number of houses that will be infected in the end, if she optimally choose the houses to protect.

翻译中…

Note that every day Cirno always chooses a house to protect before the virus spreads. Also, a protected house will not be infected forever.

翻译中…

Input

翻译中…

The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. Description of test cases follows.

翻译中…

The first line of each test case consists of two positive integers $n, m$ ($5 \leq n \leq 10^9$, $1 \leq m \leq \min(n, 10^5)$) — the number of houses on the circle, and the number of houses that are initially infected.

翻译中…

The second line of each test case consists of $m$ distinct positive integers $a_1, a_2, \cdots , a_m$ ($1 \leq a_i \leq n$) — the indices of the houses infected initially.

翻译中…

It is guaranteed that the sum of $m$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output an integer on a separate line, which is the minimum number of infected houses in the end.

翻译中…

Note

翻译中…

In the first test case:

翻译中…

At the start of the first day, house $3$, $6$, $8$ are infected. Choose house $2$ to protect.

翻译中…

At the start of the second day, house $3$, $4$, $5$, $6$, $7$, $8$, $9$ are infected. Choose house $10$ to protect.

翻译中…

At the start of the third day, no more houses are infected.

翻译中…

In the second test case:

翻译中…

At the start of the first day, house $2$, $5$ are infected. Choose house $1$ to protect.

翻译中…

At the start of the second day, house $2$, $3$, $4$, $5$, $6$ are infected. No more available houses can be protected.

翻译中…

样例

Input #1
8
10 3
3 6 8
6 2
2 5
20 3
3 7 12
41 5
1 11 21 31 41
10 5
2 4 6 8 10
5 5
3 2 5 4 1
1000000000 1
1
1000000000 4
1 1000000000 10 16
Output #1
7
5
11
28
9
5
2
15
InputCopy OutputCopy
题目信息
题号
1704C
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
排序

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