#K34587. Minimum Final Value of an Array
Minimum Final Value of an Array
Minimum Final Value of an Array
Given an array of integers , you are allowed to perform a series of operations where in each operation you choose two elements and replace them with their sum. After performing these operations repeatedly, only one element will remain. It can be shown that the minimum possible final value is obtained by summing the two smallest elements in the array, i.e., if and are the smallest and second smallest elements respectively, then the answer is .
This problem requires you to compute this value given the initial array.
inputFormat
The first line contains an integer (), representing the number of elements in the array. The second line contains space-separated integers (), the elements of the array.
outputFormat
Output a single integer: the minimum possible final value, which is the sum of the two smallest numbers in the array.## sample
4
4 3 5 6
7
</p>