Merging Slimes
InterviewTime limit2sMemory limit512 MB
Merge N slimes two at a time, scoring the product of merged sizes, and maximize the total score.
Problem
Yeongseon and Hyobin play a slime merging game. On each turn they pick two slimes and merge them into one. The game ends when a single slime is left.
Every slime has a positive size. Merging a slime of size with a slime of size produces one slime of size , and the two players score points for that merge.
Write a program that finds the maximum total score Yeongseon and Hyobin can get.
Input
The first line contains the number of slimes ().
The second line contains the sizes of the slimes, separated by spaces. Each size is a natural number at most .
Output
Print the maximum total score Yeongseon and Hyobin can get on the first line.