Since Max is wasting his time in his List I Communication credit lecture, he decided to start taking subsequences of arrays instead!
Specifically, he has
That is, he must minimize
Can you find the minimum sum of absolute differences for every possible subsequence of length
Constraints
Subtask 1 [40%]
Subtask 2 [60%]
No additional constraints.
Input Specification
The first line will contain two integers,
The second line will contain
Output Specification
Output the minimum sum of absolute differences between consecutive elements for any subsequence of length
Sample Input 1
6 2
1 5 6 2 1 3
Sample Output 1
0
Explanation for Sample 1
It can be proven that the minimal sum is achieved with the subsequence
Sample Input 2
6 4
3 2 6 2 7 9
Sample Output 2
6
Explanation for Sample 2
It can be proven that the minimal sum is achieved with the subsequence
Comments