Histograms are generally fun to play with. But not all histograms are complete. Making a normal histogram complete, is not such an easy task. We will attempt to do it here.
Let us first define a complete histogram. A histogram is complete iff it satisfies the following conditions -
You are given a histogram, which may or may not be complete. It has to be converted into a complete histogram with minimum cost incurred. You are allowed to increase or decrease height of any bar in it. The cost of increasing any bar by unit height costs x and decreasing any bar by unit height costs y.
Input:
The first line of the input contains 6 integers, N,M,a,b,x,y, as mentioned in the problem statement.
The second line contains N integers, representing an array A of size N, where the element at index i represents Heighti.
Output:
A single integer representing the minimum cost needed to convert the histogram into a complete histogram. Print -1 if it is not possible to make a complete histogram.
Constraints:
1≤N≤105
1≤M≤105
1≤x≤105
1≤y≤105
0<a≤b≤N
0≤Heighti≤M
We can make 1st, 3rd and 5th bar of height 10 and 2nd, 4th bars of height 0. The total cost is 6+2+1+6+5=20.