P18323 [CodeChef] DEADEND
提高-
题目描述

Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Kerim is an environment-friendly guy. Today, he accepted Samir's challenge of planting 20 million trees by 2020. Currently, there are $N$ trees (numbered $1$ through $N$) planted at distinct positions on a line; for each valid $i$, the position of the $i$-th tree is $A_{i}$.

A set of trees is beautiful if for each tree in this set (let's denote its position by $x$), there is a tree at the position $x-1$ and/or a tree at the position $x+1$.

Kerim's task is to plant some (possibly zero) trees in such a way that the resulting set of all planted trees (the initial $N$ trees and those planted by Kerim) is beautiful. It is only allowed to plant trees at integer (possibly negative) positions. Find the minimum number of trees he needs to plant in order to achieve that.

------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.

------ Output ------
For each test case, print a single line containing one integer ― the minimum number of trees Kerim needs to plant.

------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
$A_{1}, A_{2}, \ldots, A_{N}$ are pairwise distinct
the sum of $N$ over all test cases does not exceed $10^{6}$

------ Subtasks ------
Subtask #1 (50 points):
$N ≤ 1,000$
$A_{i} ≤ 2,000$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{4}$

Subtask #2 (50 points): original constraints

----- Sample Input 1 ------
1

3

2 7 4
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: Kerim should plant trees at the positions $3$ and $6$ to make the grid beautiful, so the answer is $2$.

输入格式

见题面

输出格式

见题面

样例输入
1 3 2 7 4
样例输出
2