题目描述
Read problem statements in [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is playing a noob version of the game Flappy Bird with the following rules:
The bird starts at a height $H$ at $x = 0$.
There are $N$ obstacles (numbered $1$ through $N$). For each valid $i$, the $i$-th obstacle is at a position $x_{i}$ and it has a height $h_{i}$.
For each integer $i$ ($0 ≤ i < x_{N}$), Chef has the option to click once when the bird is at $x = i$. Let's denote the bird's height ($y$-coordinate) at that point by $j$. If he clicks, the bird moves to $x = i+1$ and $y = j+1$. Otherwise, the bird moves to $x = i+1$ and $y = j-1$.
There is no ceiling and all the obstacles extend upwards from the bottom and not the other way around.
For each valid $i$, the bird crosses the $i$-th obstacle successfully if the bird's height at $x = x_{i}$ is strictly greater than $h_{i}$.
At any point before $x = x_{N}$, the bird's height should remain non-negative, otherwise it will drown.
If the bird crosses the $N$-th obstacle successfully, Chef wins the game.
Can you tell Chef if he can win the game (get the bird to cross all the obstacles) and the minimum number of clicks required to win in such a case?
------ 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 two space-separated integers $N$ and $H$.
The second line contains $N$ space-separated integers $x_{1}, x_{2}, \ldots, x_{N}$.
The third line contains $N$ space-separated integers $h_{1}, h_{2}, \ldots, h_{N}$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of clicks required to cross all the obstacles successfully, or $-1$ if it is impossible to cross all the obstacles.
------ Constraints ------
$1 ≤ T ≤ 3 \cdot 10^{4}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ H ≤ 10^{9}$
$1 ≤ x_{1} < x_{2} < \ldots < x_{N} ≤ 10^{9}$
$1 ≤ h_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$
------ Example Input ------
3
1 0
2
1
2 1
1 3
1 1
5 10
1 2 3 4 5
10 11 12 13 15
------ Example Output ------
2
2
-1
------ Explanation ------
Example case 2: The figure below shows one possible way to successfully cross all the obstacles using the minimum number of clicks.
Example case 3: It is clear that even by clicking all the time, it is impossible to cross the last obstacle.
输入格式
见题面
输出格式
见题面