编程介的小学生 2017-05-05 07:26 采纳率: 20.5%
浏览 895
已采纳

It's Never Too Late

A shepherd has several sheep, and every evening when he finishes herding, he just encloses all sheep in the sheepfold and then goes to bed. The sheepfold, which can be regarded as a polygon on the ground, is made up with many pieces of wooden fences. This morning the shepherd found that one of his sheep is missing. After examining, he found that a piece of fence is broken. And the unlucky sheep is possibly eaten by a wolf which came through the broken fence last night. The shepherd soon recognized that if he does not mend the sheepfold, he will lose a sheep every night from now on. However, since the broken piece cannot be used anymore, he has to reorganize the other pieces to make a new enclosure. As shorter fences are more likely to be broken (the broken piece is the shortest one), he decide to join some of the original fences to make longer fences, and make the new sheepfold as a rectangle, which is a shape with both long edges and large area. But since the original fences are all manufactured separately, they can only be joined at the ends. And if an original piece is divided into two or more pieces, all of them will be useless. Now with all the lengths of fences in the original sheepfold measured, the shepherd wonders how large the new sheepfold can be at most. (Sheep need large space to grow well) But he is only good at herding and do not know how to calculate it, can you help him?

Input

Each test case begins with a line with only an integer N (3 <= N <= 17), the number of pieces in the original sheepfold. The next line contains N integers L1, L2 ... LN, (0 < Li <= 10,000, 1 <= i <= N), represent the length of each piece.

There are no more than 120 test cases in the input, processing to the end of file.

Output

For each test case, print a line with the maximum area of the new sheepfold on its own. If it is impossible to make a valid sheepfold, print -1 instead.

Sample Input

7
1 1 3 3 4 5 7
7
9 1 9 5 6 2 10
Sample Output

15
-1

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题