logo AlgoBeat OnlineJudge
登录 注册

#216775. [GKS 2020 #G] Combination Lock

内存限制:1024 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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?

输入格式

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 .

输出格式

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.

样例

样例输入 1

2
3 5
2 3 4
4 10
2 9 3 8

样例输出 1

Case #1: 2
Case #2: 8

数据范围与提示

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

.

.