#P16773. [GKS 2020 #G] Combination Lock
[GKS 2020 #G] Combination Lock
Problem Description
A combination lock has wheels, each of which has the integer values through on it, in ascending order.
At any moment, each wheel shows a specific value on it. is the initial value shown on the -th wheel.
You can use a single move to change a wheel from showing the value to showing either or , wrapping around between and . For example, if a wheel currently shows the value , in one move you can change its value to or .
Given all wheels' initial values, what is the minimum number of moves to get all wheels to show the same value?
Input Format
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains the two integers and .
The second line contains integers. The -th integer is .
Output Format
For each test case, output one line containing Case #: , where is the test case number (starting from ) and is the minimum number of moves to get all wheels to show the same value.
2
3 5
2 3 4
4 10
2 9 3 8
Case #1: 2
Case #2: 8
Hint
In Sample Case #, the best solution is to get all wheels to show value , which would take a total of moves: the first wheel would move once (from value to value ), the second wheel would not move (it already shows value ), and the third wheel would move once (from value to value ).
For reference, it would take moves to get all wheels to show value , moves to get all wheels to show value , moves to get all wheels to show value , and moves to get all wheels to show value .
In Sample Case #, the best solutions are to get all wheels to show either value , , or , which would take a total of moves.
Limits
.
.
Test Set
.
.
Test Set
.
.
Test Set
.
.