CF1734A Select Three Sticks
题目描述
给定 $n$ 根木棍,每次可以选择一根木棍进行长度 $+1$ 或 $-1$ 的操作(每次操作后,所有木棍的长度都应为整数)。
求从 $n$ 根木棒中选出 $3$ 根并在**不折断**的情况下使用它们来形成一个**等边三角形**的最小操作数。
输入格式
第一行一个正整数 $t$ $(1\leq t\leq 100)$,表示数据组数。
每组数据的第一行包含一个整数 $n$ $(3\leq n\leq 300)$,表示木棍的数量。
接下来 $n+1$ 行包含 $n$ 个整数 $a_i$ $(1\leq a_i\leq 10^9)$
数据保证,所有数据的 $n$ 之和不超过 $300$。
输出格式
对于每组数据,输出一行一个整数,为要进行的最小操作数。
说明/提示
In the first test case, you can increase the length of the first stick by $ 1 $ , then decrease the length of the third stick by $ 1 $ . In total, you perform $ 2 $ operations, such that the three sticks form an equilateral triangle of side length $ 2 $ .
In the fourth test case, you can decrease the length of the seventh stick by $ 1 $ . An equilateral triangle of side length $ 1 $ can be selected and formed by the second, fourth, and seventh sticks.