题目描述
Given $K$ arrays of length $N$ where the elements are bounded in the range $[L, R]$.
The Function value of an array is defined as the sum of all elements present in it.
In one move you can change at most $1$ element from all the arrays and the changed value must lie within the range $[L, R]$.
What is the minimum number of operations required to make the function value of all arrays equal?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains four space-separated integers $K$, $N$, $L$, $R$.
Next $K$ lines contains an array of length $N$.
------ Output ------
For each test case, print the minimum number of operations needed to make the function value of all arrays equal in a new line.
------ Constraints ------
$1 ≤ T ≤ 5$
$1 ≤ K ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ N*K ≤ 10^{5}$
$1 ≤ L ≤ R ≤ 10^{9}$
------ Example Input ------
1
4 3 1 9
1 1 2
1 2 3
1 2 4
1 2 2
------ Example Output ------
1
------ Explanation ------
Change array $1$ to $[1, 3, 2]$
No change in array $2$
Change array $3$ to $[1, 2, 3]$
Change array $4$ to $[1, 2, 3]$
Sum of all arrays is equal.
输入格式
见题面
输出格式
见题面