码迷,mamicode.com
首页 > 其他好文 > 详细

8月5号团队赛补题

时间:2018-08-05 18:12:37      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:number   足球   ber   多少   xmlns   long   namespace   tom   htm   

 1.Commentary Boxes

Description

Berland Football Cup starts really soon! Commentators from all over the world come to the event.

Organizers have already built nn commentary boxes. mm 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 nn is not divisible by mm, it is impossible to distribute the boxes to the delegations at the moment.

Organizers can build a new commentary box paying aa burles and demolish a commentary box paying bb 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 mm)?

Input

The only line contains four integer numbers nn, mm, aa and bb (1n,m10121≤n,m≤1012, 1a,b1001≤a,b≤100), where nn is the initial number of the commentary boxes, mm is the number of delegations to come, aa is the fee to build a box and bb 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 mm). It is allowed that the final number of the boxes is equal to 00.

Sample Input

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

Hint

In the first example organizers can build 55 boxes to make the total of 1414 paying 33 burles for the each of them.

In the second example organizers can demolish 22 boxes to make the total of 00 paying 77 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 55 boxes.

 

题目意思:足球赛之前要给每一支代表队分配评论框,每一支代表队都必须得到数量相同的评论框,现在有n个评论框,m支代表队,可以新建一些评论框代价是a,也可以拆除一些评论框代价是b。问最后至少花费多少。

解题思路:分别算出新建一些和拆除一些评论框的花费,找到最少的花费就行了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long int
using namespace std;
int main()
{
    ll n,m,a,b,x,y,ans1,ans2,ans;
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    x=n%m;
    y=n/m;
    ans1=x*b;///
    ans2=((y+1)*m-n)*a;//
    ans=min(ans1,ans2);
    printf("%lld\n",ans);
    return 0;
}

 

8月5号团队赛补题

标签:number   足球   ber   多少   xmlns   long   namespace   tom   htm   

原文地址:https://www.cnblogs.com/wkfvawl/p/9426463.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!