You are given two arrays \(A, B\), each containing \(N\) integers. You want to minimize the maximum absolute difference between two adjacent integers of the array \(A\) (i.e. \(\max_{i=1}^{ N-1} \mid A_i - A_{i+1} \mid\)). You can do the following operation atmost \(K\) times:
- Choose an index \(i \;(1 \le i \le N)\) and swap \(A_i, B_i\).
Find the minimum possible value of \(\max_{i=1}^{ N-1} \mid A_i - A_{i+1} \mid.\)
Input format
- The first line contains \(T\) denoting the number of test cases. The description of \(T\) test cases is as follows:
- For each test case:
- The first line contains two integers \(N,K\) denoting the size of array \(A\) and the maximum number of operations to be performed respectively.
- The second line contains \(N\) space-separated integers \(A_1, A_2, \dots, A_N\) - denoting the elements of the array \(A.\)
- The third line contains \(N\) space-separated integers \(B_1, B_2, \dots, B_N\) - denoting the elements of the array \(B.\)
Output format
For each test case, print the minimum possible value of \(\max_{i=1}^{ N-1} \mid A_i - A_{i+1} \mid.\)
Constraints
In the first test case, applying the operation on index i = 2 makes A = [5, 3]. Thus the answer is |5 - 3| = 2.
In the second test case, applying the operation on index i = 2 and index i = 4 makes A = [5, 7, 4, 3]. Thus the answer is max(|5 - 7|, |7 - 4|, |4 - 3|) = max(2, 3, 1) = 3.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor