#P3543. Ground Leveling Operations
Ground Leveling Operations
Ground Leveling Operations
Byteasar wants to build a house in a very narrow valley. Before starting construction he needs to level the ground. To do so he may use two excavators. One excavator can change the ground level of any contiguous region by exactly meters (either increasing or decreasing it), and the other can change it by exactly meters (again, either increasing or decreasing it). The operations do not require the ground to be leveled at intermediate steps; in other words, the ground level at any point may temporarily be nonzero or even negative.
You are given an integer and an array of integers where the th element denotes the current elevation at point . In one operation you choose any contiguous segment of the valley (that is, a subarray of ) and add one of the four allowed values: , , , or to every element of that segment. Your task is to determine the minimum number of operations needed so that after applying them the entire valley is leveled (i.e. every element becomes ).
It is guaranteed that a solution exists. (Note that both and may be used arbitrarily many times, and you may choose different segments for each operation.)
inputFormat
The input begins with a line containing three integers , , and , where is the number of points in the valley, and and are the fixed adjustment amounts. The second line contains integers , where is the initial ground level at point .
outputFormat
Output a single integer --- the minimum number of operations required to level the ground (make all ).
sample
3 3 5
-5 0 5
2
</p>