#C10082. Equalize the Array Minimization Problem
Equalize the Array Minimization Problem
Equalize the Array Minimization Problem
You are given an array of integers. You can decrease any element by 1 any number of times. Your goal is to make all elements equal while minimizing the total sum of the array.
Task: Find the minimum possible sum after performing the operations optimally.
Hint: The optimal solution is to reduce every element to the minimum value in the array. Mathematically, if \(m = \min\{a_1, a_2, \dots, a_n\}\) and \(n\) is the number of elements, then the answer is given by \(m \times n\).
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) (\(1 \le n \le 10^5\)) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\) where each \(a_i\) satisfies \(1 \le a_i \le 10^9\).
outputFormat
Output a single integer which is the minimum possible sum of the array after reducing all elements to the same value.
## sample3
5 3 7
9