Laziness
Time limit1sMemory limit512 MB
Cut a bar of total length into given pieces with cut cost xy and minimize total cost; the cost is fixed at (sum of squares differences)/2, so just read the lengths.
- Level
Hard8 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
For some reason, Hyunwoo has ended up needing iron bars of lengths . But all he had was a single iron bar of length . Hyunwoo will cut this bar himself to make the bars he originally needed. Cutting a bar of length into two bars of lengths and costs , the product of the lengths of the two bars he wants to make. Hyunwoo wants to cut this bar at minimum cost to obtain the bars of lengths .
However, Hyunwoo is not sure how much this cost will be. So he has offered to raise your Code Jam contest score by 30 points if you write a program that computes the minimum cost of cutting the bar. How about it?
Input
The first line gives the integer , the number of iron bars Hyunwoo wants. ()
The second line gives the integers , the lengths of the iron bars Hyunwoo wants. ()
Output
Print the minimum cost for Hyunwoo to obtain the iron bars he needs.