#B4103. Equalize Product Specifications
Equalize Product Specifications
Equalize Product Specifications
Little Ming works in a manufacturing assembly line where each product has a specification represented by a positive integer. On a given day, the assembly line produces n products where the specification of the i-th product is given by a_i. Little Ming wants to standardize all products so that they have the same specification.
To achieve this, he can use two types of tools as many times as he wants:
- Use the first tool costing A to increase the specification of any product by 1 (i.e. change a_i to a_i+1).
- Use the second tool costing B to decrease the specification of any product by 1 (i.e. change a_i to a_i-1).
The goal is to make all product specifications equal with minimum total cost. Formally, if all specifications are adjusted to an integer t, the total cost is given by:
[ \text{Cost}(t) = \sum_{i=1}^n \begin{cases} A \times (t - a_i), & \text{if } a_i < t\ B \times (a_i - t), & \text{if } a_i > t \ 0, & \text{if } a_i = t \end{cases} ]
Your task is to compute the minimum cost to make all product specifications equal.
inputFormat
The first line contains three space-separated integers: n, A, and B where n is the number of products, A is the cost to increment a product's specification by 1, and B is the cost to decrement a product's specification by 1.
The second line contains n space-separated positive integers a1, a2, ..., an representing the specifications of the products.
outputFormat
Output a single integer representing the minimum cost required to make all the product specifications equal.
sample
3 1 1
1 2 3
2