King
시간 제한1초메모리 제한2048 MB
각 k에 대해 길이가 k 이상인 모든 부분배열에서 k번째로 큰 값이 같아지도록 배열을 바꾸는 최소 비용을 구한다.
문제
Samuel recently became the king in the distant country of Reyjrland (pronounced "Ragerland"). He must make sure that the cities represent his likeness as part of the "Inaugural Collection of Preparatory Chores" needed to be done by the king.
Reyjrland can be represented as an array of integers of length , corresponding to the values of the cities in the country. If we define to be the largest value in an array of length at least , then the cities are said to represent the king's likeness if is the same for all subarrays of which are of length at least .
The current values of the cities, may not yet represent the king's likeness. To fix this, each day, the king may choose a city and increment or decrement the city's values by 1.
After working for many days inefficiently randomly modifying the values on cities until the array represented his likeness, Samuel swore he would never let future kings go through the same thing. He tasks you to find the minimum number of days to transform the current city values into an array that represents the king, for all from through . Modifications from making the array represent the likeness of the king do not carry over to any other king. That is, after each king's reign, the city values are reset to the values in the original array .
: An array is a subarray of an array if can be obtained from by deleting several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
입력
The first line of input contains one integer (), the number of cities which is also the length of the array of values.
The next lines contain one integer each. The line contains (), the value of the city.
출력
Output lines containing one integer each. The line should contain the minimum number of days for the king to make the array represent his likeness.