CF1355E.Restorer Distance

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have to restore the wall. The wall consists of NN pillars of bricks, the height of the ii -th pillar is initially equal to hih_{i} , the height is measured in number of bricks. After the restoration all the NN 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 AA ;
  • remove a brick from the top of one non-empty pillar, the cost of this operation is RR ;
  • move a brick from the top of one non-empty pillar to the top of another pillar, the cost of this operation is MM .

You cannot create additional pillars or ignore some of pre-existing pillars even if their height becomes 00 .

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 NN , AA , RR , MM ( 1N1051 \le N \le 10^{5} , 0A,R,M1040 \le A, R, M \le 10^{4} ) — the number of pillars and the costs of operations.

The second line contains NN integers hih_{i} ( 0hi1090 \le h_{i} \le 10^{9} ) — 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
首页