8月5号团队赛补题

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 (1≤n,m≤10121≤n,m≤1012, 1≤a,b≤1001≤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;
}

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

时间: 2024-07-31 06:41:20

8月5号团队赛补题的相关文章

第十届山东省acm省赛补题(2)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4124 L Median Time Limit: 1 Second      Memory Limit: 65536 KB Recall the definition of the median of  elements where  is odd: sort these elements and the median is the -th largest element.

[水]浙大校赛补题

本来以为会巨难无比又有别的比赛可以打于是赛后补题,结果发现似乎略水,反正是找到了四个水题先贴下来 ZOJ-4099 J #include<iostream> #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; int t; ll x, y, n; int main() { cin >> t; while (t--) { scanf("%lld

2018山东省赛补题

题目链接 https://www.nowcoder.com/acm/contest/123/E 题解 https://www.cnblogs.com/Rubbishes/p/9074460.html #include <bits/stdc++.h> using namespace std; const int MAXN=1000005; int cnt[MAXN]; int main() { int t; while(~scanf("%d",&t)) { while

2016 杭州区域赛补题

A - ArcSoft's Office Rearrangement HDU - 5933 题意:现在有n个办公区,每个办公区内有a[i]个办公人员,现在要将这些人均匀的分布在m个办公区内,每个办公区人员必须等价.现在有两个操作,1操作,可以将相邻的两个区域的人员结合在一起,2操作可以将一个办公区的人员,随意划分成两部分,两部分不一定平均,问最少需要多少次操作. 做法:贪心,从前向后枚举,不可以的情况就是不能平均的,可以预处理出来平均值,对于可以的情况,如果比平均值小,就直接加在后一个办公区内,

2020年3月14日 BAPC2019 比赛补题报告

Inquiry I 题意: 给定一个数列, 求公式的最大值 思路: 可以维护一个前缀和 与 后缀和, 扫描一次数组, 即可求出最大值 代码: n = int(input()) lst = [*map(int, input().split())] # left 记录数组元素平方的前缀和, right 记录数组元素后缀和 left, right = 0, sum(lst) res = 0 for i in lst: left += i**2 right -= i res = max(res, lef

hdu5017:补题系列之西安网络赛1011

补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为min(a,b,c) 所以我们需要把原方程化为标准型. 这时候线代就排上用场了,注意到原方程是一个二次型. 化为标准型 1/(k1)*x^2+1/(k2)*y^2+1/(k3)*z^2=1 后  min(k1,k2,k3)即为答案 而这里的1/k1,1/k2,1/k3 就是二次型矩阵的特征值 如何求特

4号团队-团队任务3:每日立会(11月26日至12月7日)

团队序号:04 开发的软件名称:飞机大战 团队信息: 团队只有UI设计师王菊,产品经理王擎,软件工程师.共三人 每日例会11月26日至12月7号的链接: 26日   https://www.cnblogs.com/jbbrnbs/p/10028609.html 27日   https://www.cnblogs.com/jbbrnbs/p/10028671.html 28日   https://www.cnblogs.com/jbbrnbs/p/10030865.html 原文地址:https:

补psp进度(11月4号-9号)

这周psp进度 11月4号 内容 开始时间 结束时间 打断时间 净时间 小伙伴聊天实现 9:45 10:49 0 64m 学习HttpURLConnection 14:13 15:48 10m 85m 11月7号 内容 开始时间 结束时间 打断时间 净时间 和组长测试约跑软件 9:50 10:30 0 40m 开组内站立会议 12:00 12:30 0 30m 11月8号 内容 开始时间 结束时间 打断时间 净时间 学习xml 14:10 16:45 约30m 125m 开组内站立会议 12:0

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh童鞋的提醒. 勘误2:第7题在推断连通的时候条件写错了,后两个if条件中是应该是<=12 落了一个等于号.正确答案应为116. 1.煤球数目 有一堆煤球.堆成三角棱锥形.详细: 第一层放1个, 第二层3个(排列成三角形), 第三层6个(排列成三角形), 第四层10个(排列成三角形). -. 假设一共