#P3543. Ground Leveling Operations

    ID: 16797 Type: Default 1000ms 256MiB

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 aa meters (either increasing or decreasing it), and the other can change it by exactly bb 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 nn and an array hh of nn integers where the iith element denotes the current elevation at point ii. In one operation you choose any contiguous segment of the valley (that is, a subarray of hh) and add one of the four allowed values: +a+a, a-a, +b+b, or b-b 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 00).

It is guaranteed that a solution exists. (Note that both aa and bb 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 nn, aa, and bb, where nn is the number of points in the valley, and aa and bb are the fixed adjustment amounts. The second line contains nn integers h1,h2,,hnh_1, h_2, \dots, h_n, where hih_i is the initial ground level at point ii.

outputFormat

Output a single integer --- the minimum number of operations required to level the ground (make all hi=0h_i=0).

sample

3 3 5
-5 0 5
2

</p>