#P13967. [VKOSHP 2024] Two Arrays

[VKOSHP 2024] Two Arrays

题目描述

Let the maximum in the array dd be denoted as max(d)\max(d) and the minimum as min(d)\min(d).

Two arrays aa and bb of length nn are given. In one operation, you can choose an index 1in1 \leq i \leq n and simultaneously increase the elements aia_i and bib_i by one: ai=ai+1a_i = a_i + 1, bi=bi+1b_i = b_i + 1. It is necessary to use these operations to achieve the simultaneous fulfillment of two conditions:

  • max(a)min(a)x\max(a) - \min(a) \leq x,
  • max(b)min(b)y\max(b) - \min(b) \leq y.

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 tt --- the number of test cases (1t1051 \leq t \leq 10^5). The description of the test cases follows.

The first line of each test case contains three integers: nn, xx, yy (1n1051 \leq n \leq 10^5, 0x,y1090 \leq x, y \leq 10^9).

The second line of each test case contains nn integers a1,a2,ana_1, a_2, \dots a_n --- the elements of array aa (109ai109-10^9 \leq a_i \leq 10^9).

The third line of each test case contains nn integers b1,b2,bnb_1, b_2, \dots b_n --- the elements of array bb (109bi109-10^9 \leq b_i \leq 10^9).

It is guaranteed that the sum of nn across all test cases does not exceed 10510^5.

输出格式

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 1-1.

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