FJ is going to take a good look at some rugged dirt road in the farm. According to the demands of the cows, the repaired
The height of the pavement should be monotonically increasing or monotonically decreasing, that is to say, height rise and height descent cannot
At the same time appeared in the repaired road.
The whole road is divided into n segments, n integers a_1, ..., A_n (1 <= N <= 2,000) are described in turn
The height of each section of the road (0 <= a_i <= 1,000,000,000). FJ wants to find an exact n
The element does not rise or fall in sequence b_1, ..., b_n, as the height of each section of the road being repaired.
The total cost of road repairs can be expressed by the same amount of overhead or digging down one unit per section:
| a_1-b_1| + | a_2-b_2| + ... + | a_n-b_n|
Would you please calculate the minimum cost of FJ in this project? FJ assures you that this expense
No more than 2^31-1.
Initial discretization;
No descending sequence:
Setting F[i][j] means the minimum cost of repairing to block I, when he is repaired to the height of the section J or below;
F[i][j]=min (F[i][j],f[i-1][j]+abs (a[i]-q[j));
Then the analogy does not rise;
[Usaco2008feb_gold] Pavement Trimming