CF1355E.Restorer Distance
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
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?
你需要修复这堵墙。这堵墙由 N 根砖柱组成,第 i 根柱子的初始高度为 hi(以砖块数量计量)。修复完成后,所有 N 根柱子的高度必须相等。
你被允许执行以下操作:
- 在某一根柱子顶部放置一块砖,该操作花费为 A;
- 从一根非空柱子的顶部移除一块砖,该操作花费为 R;
- 将一块砖从一根非空柱子的顶部移动到另一根柱子的顶部,该操作花费为 M。
你不能新增柱子,也不能忽略任何已存在的柱子(即使其高度变为 0)。
修复这堵墙所需的最小总花费是多少?换言之,使所有柱子高度相等所需的最小总花费是多少?
输入格式
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.
输入的第一行包含四个整数 N、A、R、M(1≤N≤105,0≤A,R,M≤104)——分别表示柱子的数量以及各操作的代价。
第二行包含 N 个整数 hi(0≤hi≤109)——表示各柱子的初始高度。
输出格式
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
输入解题思路,AI测评打分。不知道怎么写?