题目描述
In China, people use pairs of chopsticks to eat food, but Mr. L is a bit different. He uses a set of three chopsticks, one pair plus an extra; a long chopstick to get large items by stabbing the food. The length of the two shorter, standard chopsticks should be as close as possible, but the length of the extra one is not important so long as it is the longest. For a set of chopsticks with lengths A, B, C ( A<=B<=C), the function (A – B)2 defines the “badness" of the set.
Mr. L has invited K people to his birthday party, and he is eager to introduce his way of using chopsticks. He must prepare K + 8 sets of chopsticks (for himself, his wife, his little son, little daughter, his mother, father, mother-in-law, father-in-law, and K other guests). But Mr. L's chopsticks are of many different lengths! Given these lengths, he must find a way of composing the K + 8 sets such that the total badness of the sets is minimized.
输入
The first line in the input contains a single integer T indicating the number of test cases ( 1<=T<=20). Each test case begins with two integers K and N ( 0<=K<=1,000, 3K + 24<=N<= 5,000) giving the number of guests and the number of chopsticks. Then follow N positive integers Li, in non-decreasing order, indicating the lengths of the chopsticks ( 1<=Li<=32,000).
输出
For each test case in the input, print a line containing the minimal total badness of all the sets.
样例输入
1
1 40
1 8 10 16 19 22 27 33 36 40 47 52 56 61 63 71 72 75 81 81 84 88 96 98
103 110 113 118 124 128 129 134 134 139 148 157 157 160 162 164
样例输出
23
Note: A possible collection of the nine chopstick sets for this sample input is (8, 10, 16), (19, 22, 27), (61, 63, 75), (71, 72, 88), (81, 81, 84), (96, 98, 103), (128, 129, 148), (134, 134, 139), and (157, 157, 160).
参考代码
暂无
解析
暂无