Upload code_segments/segment_110.txt with huggingface_hub
Browse files
code_segments/segment_110.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are given an array of integers $a_1, a_2, \ldots, a_n$ and an integer $k$. You need to make it beautiful with the least amount of operations.
|
| 2 |
+
|
| 3 |
+
Before applying operations, you can shuffle the array elements as you like. For one operation, you can do the following:
|
| 4 |
+
|
| 5 |
+
* Choose an index $1 \leq i \leq n$, * Make $a_i = a_i + k$.
|
| 6 |
+
|
| 7 |
+
The array $b_1, b_2, \ldots, b_n$ is beautiful if $b_i = b_{n - i + 1}$ for all $1 \leq i \leq n$.
|
| 8 |
+
|
| 9 |
+
Find the minimum number of operations needed to make the array beautiful, or report that it is impossible.
|
| 10 |
+
|
| 11 |
+
Each test consists of several sets of input data. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of sets of input data. Then follows their description.
|
| 12 |
+
|
| 13 |
+
The first line of each set of input data contains two integers $n$ and $k$ ($1 \leq n \leq 10^5$, $1 \leq k \leq 10^9$) — the size of the array $a$ and the number $k$ from the problem statement.
|
| 14 |
+
|
| 15 |
+
The second line of each set of input data contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array $a$.
|
| 16 |
+
|
| 17 |
+
It is guaranteed that the sum of $n$ over all sets of input data does not exceed $2 \cdot 10^5$.
|
| 18 |
+
|
| 19 |
+
For each set of input data, output the minimum number of operations needed to make the array beautiful, or $-1$ if it is impossible.
|
| 20 |
+
|
| 21 |
+
In the first set of input data, the array is already beautiful.
|
| 22 |
+
|
| 23 |
+
In the second set of input data, you can shuffle the array before the operations and perform the operation with index $i = 1$ for $83966524$ times.
|
| 24 |
+
|
| 25 |
+
In the third set of input data, you can shuffle the array $a$ and make it equal to $[2, 3, 1]$. Then apply the operation with index $i = 3$ to get the array $[2, 3, 2]$, which is beautiful.
|
| 26 |
+
|
| 27 |
+
In the eighth set of input data, there is no set of operations and no way to shuffle the elements to make the array beautiful.
|
| 28 |
+
|
| 29 |
+
In the ninth set of input data, the array is already beautiful.
|