#C11696. Maximum Perfection Index
Maximum Perfection Index
Maximum Perfection Index
You are given an array of n integers. The perfection index of an array is defined as the sum of the absolute differences between consecutive elements. In other words, for an array a[0], a[1], …, a[n-1], its perfection index is given by:
\(\sum_{i=1}^{n-1} |a[i] - a[i-1]|\)
Your task is to compute and print the perfection index of the given array.
Example:
Input: 5 1 3 2 4 7</p>Output: 8
In the above example, the differences are: |3-1| = 2, |2-3| = 1, |4-2| = 2, |7-4| = 3 so the perfection index is 2+1+2+3 = 8.
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.
outputFormat
Output a single integer, which is the perfect index of the array.
## sample5
1 3 2 4 7
8