QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#13308. Leveling Ground

Statistics

Byteasar has decided to build a house. He has chosen a very narrow valley as its location. Before Byteasar starts the actual construction work, he has to level the ground first. He has two excavators at his disposal: the first one can either increase or decrease the ground level of any connected area in the valley by exactly a meters; the other can do the same, i.e., either increase or decrease the ground level of any connected area in the valley, but by exactly b meters. Notice that neither before such an operation nor after it needs the ground in the affected area be actually leveled.

Given a map of the area, determine the minimum number of operations required to level the ground in the whole valley, i.e., to make the ground level everywhere equal 0. While the operations are performed, the ground level at any point in the valley can have arbitrary value; in particular, it may be negative.

Input Format

In the first line of the standard input there are three integers, $n$, $a$, $b$ ($1 ≤ n ≤ 100\,000$, $1 ≤ a,b ≤ 10^{9}$), separated by single spaces. The number n denotes the valley's length in meters. The second line contains $n$ integers, $h_{1},h_{2},…,h_{n}$, separated by single spaces. These numbers, all with absolute value no larger than $10^{9}$, represent the initial ground level in meters of successive one meter long slices of the valley.

In tests worth 30% of the points the following conditions hold in addition: $n,a,b ≤ 200$ and $-200 ≤ h_{1},…,h_{n} ≤ 200$.

In tests worth 60% of the points the following conditions hold in addition: $n,a,b ≤ 2\,000$ and $-2,000 ≤ h_{1},…,h_{n} ≤ 2\,000$.

In tests worth 90% of the points the condition $a,b ≤ 10^{6}$ holds in addition.

Output Format

In the first and only line of the standard output your program should print a single integer: the minimum number of operations required to level the ground in the whole valley, or -1 if leveling the whole valley with given excavators is impossible.

Example

Input

5 2 3
1 2 1 1 -1

Output

5

Notes

One possible solution for the exemplary input is:

  • increase the ground level of the first two meters of the valley by 2 meters,
  • decrease the ground level of the first two meters of the valley by 3 meters,
  • increase the ground level of the last four meters of the valley by 2 meters,
  • increase the ground level of the last meter of the valley by 2 meters,
  • decrease the ground level of the last four meters of the valley by 3 meters.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.