#P9976. [USACO23DEC] Farmer John Actually Farms B
[USACO23DEC] Farmer John Actually Farms B
Problem Description
Farmer John is growing () asparagus plants on his farm. However, some plants have genetic differences and grow faster than others. The initial height of plant is inches, and then every day, plant grows by inches.
FJ likes some of these plants more. He will give you an array consisting of distinct integers; this array contains all integers from to . He wants exactly plants to be taller than plant . Find the minimum number of days needed to satisfy FJ’s requirement, or report that it is impossible.
Input Format
Each test contains multiple test cases.
The first line contains an integer , the number of test cases ().
For each test case, the first line contains an integer (), the number of plants.
The second line contains integers (), the initial height of plant .
The third line contains integers (), the height increase per day of plant .
The fourth line contains distinct integers , the array given by FJ.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
Output lines, each line containing the answer for one test case. If the requirement is impossible to satisfy, output .
Note that because the integers in this problem can be very large, you may need to use 64-bit integer types (for example, long long in C/C++).
6
1
10
1
0
2
7 3
8 10
1 0
2
3 6
10 8
0 1
2
7 3
8 9
1 0
2
7 7
8 8
0 1
2
7 3
8 8
1 0
0
3
2
5
-1
-1
2
5
7 4 1 10 12
3 4 5 2 1
2 1 0 3 4
5
4 10 12 7 1
3 1 1 4 5
2 4 3 1 0
4
7
Hint
Sample Explanation 1
In the first sample, there are test cases.
In the first test case, there is only one plant, so the requirement is already satisfied on day .
In the second test case, the first plant needs to be shorter than the second plant. After day , their heights are ; after day , their heights are both ; after day , their heights are , which is the first day that satisfies the requirement.
The third and fourth test cases are similar to the second test case.
In the fifth test case, both plants start at inches and both grow by inches per day, so their heights are always the same. Therefore, the condition can never be satisfied.
In the sixth test case, the initial heights do not satisfy the requirement and the growth rates are the same, so the condition can never be satisfied.
Sample Explanation 2
In the second sample, there are test cases.
In the first test case, the final heights after day are .
In the second test case, the final heights after day are .
Test Point Properties
- Test point satisfies .
- Test points satisfy , and .
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5