若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1580: Chopsticks

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,307

题目描述

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). 


参考代码

暂无

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Dreams孤独患者 原站点 Skip
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist