The unbalance of an array is the maximum value of the array minus the minimum. Given an array of length , can you find the unbalance of every subarray of length ?
A subarray of an array is defined as a set of consecutive elements in
The first line contains two integers: and .
The second line contains integers, the elements of .
integers, the -th of which is the unbalance of the subarray from the -th index to the -th index.
2 6 4 4 1
4 2 3
The three subarrays of length are: , , and .
The first one has a maximum of and a minimum of , so its unbalance is The second one has an unbalance of And the third has an unbalance of