#K63082. Transform and Sum
Transform and Sum
Transform and Sum
You are given an array of integers. Your task is to transform the array by replacing each element ai with the absolute difference between its original value and the maximum value in the array. In other words, each element is replaced by \( |a_i - M| \), where \( M = \max\{a_1, a_2, \ldots, a_n\} \). After transforming the array, output the sum of all the resulting values.
Example:
For the array [3, 1, 2, 4], the maximum element is 4. The transformed array becomes [|3-4|, |1-4|, |2-4|, |4-4|] which is [1, 3, 2, 0]. The sum of these values is 6.
inputFormat
The first line contains a single integer \( n \) representing the number of elements in the array. The second line contains \( n \) space-separated integers representing the elements of the array.
outputFormat
Output a single integer which is the sum of the transformed array as described above.
## sample4
3 1 2 4
6