CF1355E.Restorer Distance
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have to restore the wall. The wall consists of N pillars of bricks, the height of the i -th pillar is initially equal to hi , the height is measured in number of bricks. After the restoration all the N pillars should have equal heights.
You are allowed the following operations:
- put a brick on top of one pillar, the cost of this operation is A ;
- remove a brick from the top of one non-empty pillar, the cost of this operation is R ;
- move a brick from the top of one non-empty pillar to the top of another pillar, the cost of this operation is M .
You cannot create additional pillars or ignore some of pre-existing pillars even if their height becomes 0 .
What is the minimal total cost of restoration, in other words, what is the minimal total cost to make all the pillars of equal height?
输入格式
The first line of input contains four integers N , A , R , M ( 1≤N≤105 , 0≤A,R,M≤104 ) — the number of pillars and the costs of operations.
The second line contains N integers hi ( 0≤hi≤109 ) — initial heights of pillars.
输出格式
Print one integer — the minimal cost of restoration.
输入输出样例
输入#1
3 1 100 100 1 3 8
输出#1
12
输入#2
3 100 1 100 1 3 8
输出#2
9
输入#3
3 100 100 1 1 3 8
输出#3
4
输入#4
5 1 2 4 5 5 3 6 5
输出#4
4
输入#5
5 1 2 2 5 5 3 6 5
输出#5
3