【codeforces 758A】Holiday Of Equality
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king’s present. The king can only give money, he hasn’t a power to take away them.
Input
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.
The second line contains n integers a1, a2, …, an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
Output
In the only line print the integer S — the minimum number of burles which are had to spend.
Examples
input
5
0 1 2 3 4
output
10
input
5
1 1 0 1 1
output
1
input
3
1 3 1
output
4
input
1
12
output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
【题目链接】:http://codeforces.com/contest/758/problem/A
【题解】
最后要求所有元素都相同;
让所有的元素都变成最大值就好了;(不能减少只能增加)
【完整代码】
#include <bits/stdc++.h>
using namespace std;
int n,a[110];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
scanf("%d",&n);
for (int i = 1;i <= n;i++)
scanf("%d",&a[i]);
int ma = a[1];
for (int i = 2;i <= n;i++)
ma = max(ma,a[i]);
int sum = 0;
for (int i = 1;i <= n;i++)
if (a[i]<ma)
sum += ma-a[i];
cout << sum << endl;
return 0;
}
【codeforces 758A】Holiday Of Equality的更多相关文章
- Codeforces 758A:Holiday Of Equality(水题)
http://codeforces.com/problemset/problem/758/A 题意:给出n个值,求这里面每个值都要变成最大的那个数,总共需要加上多少. 思路:找出最大的直接算. #in ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【27.40%】【codeforces 599D】Spongebob and Squares
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 764B】Timofey and cubes
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 762B】USB vs. PS/2
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- IOS开发UI基础--数据刷新
IOS开发UI基础--数据刷新 cell的数据刷新包括下面几个方面 加入数据 删除数据 更改数据 全局刷新方法(最经常使用) [self.tableView reloadData]; // 屏幕上的全 ...
- ospp.vbs是什么文件?激活过程cscript ospp.vbs命令详解
ospp.vbs是什么文件?激活过程cscript ospp.vbs命令详解 在Office 2013激活过程中我们经常会用到cscript ospp.vbs这个命令.那么,很有必要来了解一下,osp ...
- node版本升级后,原有项目打不开
node版本升级后,原有项目出现以下问题 gulp[8272]: src\node_contextify.cc:628: Assertion `args[1]->IsString()' fail ...
- TC Hangs when using quick search extended on win10 (1703)
https://ghisler.ch/board/viewtopic.php?t=47682 I recently updated windows 10 to the latest released ...
- scrapy-爬取斗图
scrapy-爬取斗图代码 <一> 开局三连杀 1.创建run的文件
- CSS笔记 - fgm练习 2-9 - 播放列表收缩展开
练习地址: http://www.fgm.cc/learn/lesson2/09.html <style> *{ margin: 0;padding: 0;font-size: 12px; ...
- Linux 命令笔记(1)
[root@Oracle11_2 ~]# ll total -rw-------. root root May : anaconda-ks.cfg drwxr-xr-x. root root May ...
- 关于mybatis中,批量增删改查以及參数传递的问题
1.參数传递的问题 大多数情况下,我们都是利用map作为參数,而且大部分情况下都是仅仅有一个參数. 可是,我们也能够利用@param注解,来传入多个參数,此时,mybatis会自己主动将參数封装成ma ...
- msys 中打开系统程序
按照msys 后发现sh自带的vim不好用,下载安装了个gvim,在etc/profile中作如下设置: alias gvim="D:/Program\ Files/Vim/vim73/gv ...
- Ruby(面向对象程序设计的脚本语言)入门
Ruby是一种为简单快捷的面向对象编程(面向对象程序设计)而创的脚本语言. 简单介绍 Ruby 是开源的,在Web上免费提供,但须要一个许可证. Ruby 是一种通用的.解释的编程语言. Ruby 是 ...