Connect sticks with the minimum total cost. Each time take the two shortest sticks, glue them together, and add their length to the cost.
Example 1
Input: sticks = [1,8,3,5]
Output: 30
Explanation: The gluing sequence gives a total cost of 30.
Output: 30
Explanation: The gluing sequence gives a total cost of 30.
Example 2
Input: sticks = [2,4,3]
Output: 14
Explanation: First 2+3=5 (cost 5), then 4+5=9 (cost 9). Total 14.
Output: 14
Explanation: First 2+3=5 (cost 5), then 4+5=9 (cost 9). Total 14.