CF990A.Commentary Boxes
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built n commentary boxes. m regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If n is not divisible by m, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying a burles and demolish a commentary box paying b burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by m)?
贝尔兰德足球杯即将开始!来自世界各地的解说员将齐聚本次赛事。
主办方已经建好了 n 个解说室。将有 m 个地区代表团前来参加本届杯赛。每个代表团应分得相同数量的解说室。如果存在任何未被占用的解说室,则各代表团将会不满。因此,每个解说室必须且只能由一个代表团占用。
若 n 不能被 m 整除,则目前无法将解说室公平地分配给各代表团。
主办方可以通过支付 a 卢布来新建一个解说室,也可以通过支付 b 卢布来拆除一个解说室。他们可以任意多次执行新建和/或拆除操作(每次操作均需支付相应费用)。允许拆除所有现有的解说室。
为满足所有代表团的要求(即:使解说室总数能被 m 整除),主办方需要支付的最少卢布数是多少?
输入格式
The only line contains four integer numbers n, m, a and b (1≤n,m≤1012, 1≤a,b≤100), where n is the initial number of the commentary boxes, m is the number of delegations to come, a is the fee to build a box and b is the fee to demolish a box.
唯一的一行包含四个整数 n、m、a 和 b(1≤n,m≤1012,1≤a,b≤100),其中 n 是初始的解说箱数量,m 是即将到访的代表团数量,a 是建造一个解说箱的费用,b 是拆除一个解说箱的费用。
输出格式
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by m). It is allowed that the final number of the boxes is equal to 0.
输出主办方为满足所有代表团(即让盒子总数能被 m 整除)所需支付的最少 burles 数量。最终的盒子总数可以为 0。
输入输出样例
输入#1
9 7 3 8
输出#1
15
输入#2
2 7 3 7
输出#2
14
输入#3
30 6 17 19
输出#3
0
说明/提示
In the first example organizers can build 5 boxes to make the total of 14 paying 3 burles for the each of them.
In the second example organizers can demolish 2 boxes to make the total of 0 paying 7 burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get 5 boxes.
在第一个例子中,组织者可以建造 5 个箱子,使总数达到 14,每个箱子花费 3 burles。
在第二个例子中,组织者可以拆除 2 个箱子,使总数变为 0,每个箱子花费 7 burles。
在第三个例子中,组织者已经能够将所有箱子平均分配给各代表团,每个代表团获得 5 个箱子。
输入解题思路,AI测评打分。不知道怎么写?