#P12113. [NWRRC2024] If I Could Turn Back Time
[NWRRC2024] If I Could Turn Back Time
题目描述
Inna is an avid hiker. She's visiting a range of mountains with heights .
At a nearby shop, Inna has found a book that mentions that at some point in the past, the heights of the mountains were in the same order. However, there is no evidence of how old this book is.
The book also describes a model of erosion that makes the mountains shorter year after year. Every year, based on the weather, a certain height threshold can be determined. Then, every mountain with the current height of at least decreases in height by exactly . Different years can have different values of .
Inna is curious how old the book actually is, and whether the described model is sound. Help her figure out the smallest number of years in which erosion could take the mountains from heights to heights in the same order, or determine that it is impossible under the given model.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer , denoting the number of mountains ().
The second line contains integers , denoting the current heights of the mountains ().
The third line contains integers , denoting the heights of the mountains in the same order at some point in the past ().
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, print the smallest number of years in which erosion could take the mountains from heights to heights , or a single integer if the described model is unsound.
4
4
3 2 4 2
5 3 6 2
1
10
100000
5
1 2 3 4 5
1 2 3 4 5
3
1 4 6
4 1 8
2
99990
0
-1
提示
In the first test case, the heights of the mountains could go from to in just two years:
- Suppose that in the first year, . After this year, the heights of the mountains are .
- Suppose that in the second year, . After this year, the heights of the mountains are .