Farmer John has built a sand castle

时限:1000ms 内存限制:10000K  总时限:3000ms

描述:

Farmer John has built a sand castle! Like all good castles, the
walls have crennelations, that nifty pattern of embrasures (gaps)
and merlons (filled spaces); see the diagram below. The N (1 <= N
<= 25,000) merlons of his castle wall are conveniently numbered
1..N; merlon i has height M_i (1 <= M_i <= 100,000); his merlons
often have varying heights, unlike so many.
He wishes to modify the castle design in the following fashion: he
has a list of numbers B_1 through B_N (1 <= B_i <= 100,000), and
wants to change the merlon heights to those heights B_1, ..., B_N
in some order (not necessarily the order given or any other order
derived from the data).

To do this, he has hired some bovine craftsmen to raise and lower
the merlons' heights. Craftsmen, of course, cost a lot of money.
In particular, they charge FJ a total X (1 <= X <= 100) money per
unit height added and Y (1 <= Y <= 100) money per unit height
reduced.


FJ would like to know the cheapest possible cost of modifying his
sand castle if he picks the best permutation of heights. The answer
is guaranteed to fit within a 32-bit signed integer.

Note: about 40% of the test data will have N <= 9, and about 60% will have
N <= 18.

输入:

* Line 1: Three space-separated integers: N, X, and Y

* Lines 2..N+1: Line i+1 contains the two space-separated integers:
        M_i and B_i

输出:

* Line 1: A single integer, the minimum cost needed to rebuild the
        castle

输入样例:

3 6 5
3 1
1 2
1 2

输出样例:

11

提示:

INPUT DETAILS:

FJ's castle starts with heights of 3, 1, and 1. He would like to change
them so that their heights are 1, 2, and 2, in some order. It costs 6 to
add a unit of height and 5 to remove a unit of height.

OUTPUT DETAILS:

FJ reduces the first merlon's height by 1, for a cost of 5 (yielding
merlons of heights 2, 1, and 1). He then adds one unit of height
to the second merlon for a cost of 6 (yielding merlons of heights
2, 2, and 1).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值