#P13967. [VKOSHP 2024] Two Arrays
[VKOSHP 2024] Two Arrays
题目描述
Let the maximum in the array be denoted as and the minimum as .
Two arrays and of length are given. In one operation, you can choose an index and simultaneously increase the elements and by one: , . It is necessary to use these operations to achieve the simultaneous fulfillment of two conditions:
- ,
- .
Determine the minimum number of operations required to achieve the simultaneous fulfillment of the specified conditions, or find out that it is impossible.
输入格式
Each test consists of several test cases. The first line contains one integer --- the number of test cases (). The description of the test cases follows.
The first line of each test case contains three integers: , , (, ).
The second line of each test case contains integers --- the elements of array ().
The third line of each test case contains integers --- the elements of array ().
It is guaranteed that the sum of across all test cases does not exceed .
输出格式
For each test case, output one integer --- the minimum possible number of operations required to satisfy both conditions. If it is impossible to satisfy both conditions simultaneously, output .
5
4 2 3
-1 -2 -3 -4
-1 -2 -3 -4
3 3 2
1 6 4
1 4 1
4 0 3
0 2 1 2
0 2 3 3
5 2 1
-1 0 1 2 3
2 2 2 2 2
3 66 77
235 -111 9
100 -200 -100
1
3
3
-1
440