题库练习 Chef Monocarp
← 上一题 下一题 →

A13964 | Chef Monocarp

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Chef Monocarp has just put $n$ dishes into an oven. He knows that the $i$ -th dish has its optimal cooking time equal to $t_i$ minutes.

At any positive integer minute $T$ Monocarp can put no more than one dish out of the oven. If the $i$ -th dish is put out at some minute $T$ , then its unpleasant value is $|T - t_i|$ — the absolute difference between $T$ and $t_i$ . Once the dish is out of the oven, it can't go back in.

Monocarp should put all the dishes out of the oven. What is the minimum total unpleasant value Monocarp can obtain?

输入格式

The first line contains a single integer $q$ ( $1 \le q \le 200$ ) — the number of testcases.

Then $q$ testcases follow.

The first line of the testcase contains a single integer $n$ ( $1 \le n \le 200$ ) — the number of dishes in the oven.

The second line of the testcase contains $n$ integers $t_1, t_2, \dots, t_n$ ( $1 \le t_i \le n$ ) — the optimal cooking time for each dish.

The sum of $n$ over all $q$ testcases doesn't exceed $200$ .

输出格式

Print a single integer for each testcase — the minimum total unpleasant value Monocarp can obtain when he puts out all the dishes out of the oven. Remember that Monocarp can only put the dishes out at positive integer minutes and no more than one dish at any minute.

输入输出样例

输入 #1
6
6
4 2 4 4 5 2
7
7 7 7 7 7 7 7
1
1
5
5 1 2 4 3
4
1 4 4 4
21
21 8 1 4 1 5 21 1 8 21 11 21 11 3 12 8 19 15 9 11 13
输出 #1
4
12
0
0
2
21
C++ 编辑器
输入
输出