暑假训练第一场L

题目:

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

)?

Input

The only line contains four integer numbers n

, m, a and b ( 1n,m1012, 1a,b100), 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.

Output

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

.

Examples
Input
9 7 3 8
Output
15
Input
2 7 3 7
Output
14
Input
30 6 17 19
Output
0
Note

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.


思路:

这个题大意是给m个队伍分相等数量的房子,现在有n个房子,建一个房子是a元,拆房子是b元。求出最小值。

源码:

#include<iostream>
using namespace std;
int main()
{
	long long n, m, a, b, min,jian;
	cin >> n >> m >> a >> b;
	if (n%m == 0)cout << "0" << endl;
	else
	{
		min = (n%m)*b;
		jian= ((n/m+1)*m-n)*a;
		if (jian <= min)min = jian;
		cout << min << endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值