Codeforces 758A Holiday Of Equality
1 second
256 megabytes
standard input
standard 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.
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.
In the only line print the integer S — the minimum number of burles which are had to spend.
5
0 1 2 3 4
10
5
1 1 0 1 1
1
3
1 3 1
4
1
12
0
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.
题意:为了公平,最少需要多少福利,每个人都要最多的那个人手里的钱就OK了。
#include <bits/stdc++.h> using namespace std; const int maxn = + ; int n;
int a[maxn]; int main()
{ scanf("%d",&n);
int mmax = -;
for(int i=;i<n;i++) {
scanf("%d",&a[i]);
mmax = max(mmax,a[i]);
} int sum = ;
for(int i=;i<n;i++) {
sum += (mmax-a[i]);
} printf("%d\n",sum); return ;
}
1 second
256 megabytes
standard input
standard 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.
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.
In the only line print the integer S — the minimum number of burles which are had to spend.
5
0 1 2 3 4
10
5
1 1 0 1 1
1
3
1 3 1
4
1
12
0
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.
Codeforces 758A Holiday Of Equality的更多相关文章
- Codeforces 758A. Holiday Of Equality 贪心
题目大意: 给定一个长为\(n\)序列,每次操作在一个数上+1,求最小的操作次数使所有的数大小相同. 题解: 对这种题无话可说 #include <cstdio> #include < ...
- 【codeforces 758A】Holiday Of Equality
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces758A Holiday Of Equality 2017-01-20 10:08 48人阅读 评论(0) 收藏
A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces 758A:Holiday Of Equality(水题)
http://codeforces.com/problemset/problem/758/A 题意:给出n个值,求这里面每个值都要变成最大的那个数,总共需要加上多少. 思路:找出最大的直接算. #in ...
- Codeforces Round #392 (Div. 2) A B C 水 模拟 暴力
A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CodeForces758A
A. Holiday Of Equality time limit per test:1 second memory limit per test:256 megabytes input:standa ...
- CodeForces 304C
E - E Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Codeforces Gym 100187D D. Holidays 排列组合
D. Holidays Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/D ...
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
随机推荐
- vue.js vue-jsonp解决跨域问题
安装jsonp npm install vue-jsonp --save main.js中引入 import VueJsonp from 'vue-jsonp' Vue.use(VueJsonp) 组 ...
- java——ArrayList 的存在有什么意义?
好像所有的数据类型都可以用比如 TreeMap[] int[] Object[] 这种形式来创建自己的数组,那么ArrayList存在的意义是什么呢? 我只能想到这种:ArrayList可以存储多种 ...
- Docker Ubuntu/CentOS 下运行 java jar
官方安装方法 https://docs.docker.com/engine/installation/linux/ubuntu/ Ubuntu安装包 https://download.docker.c ...
- 读<<programming ruby>> 7.6节 flip-flop 理解
书中源码是这样的 File.foreach('1.txt') do |x| if(($. == 1) || x =~ /eig/) .. (($. == 3) || x =~ /nin/) then ...
- mac os 和 ubuntu 上测试工具check-0.9.10的安装
由于工作需要,要使用check 这个单元测试工具. 首先,说一说在Mac10.9上面的安装.我是直接在官网(http://check.sourceforge.net)上下载源码包. 1,解压 2,进入 ...
- No module named Crypto--转
https://blog.csdn.net/lacoucou/article/details/53152122 背景:win10+python 2.7 在python 中使用AES算法时,会报告上述错 ...
- jQuery的下拉框应用
jQuery的下拉框应用 jQuery的下拉框左右选择应用 直接上代码 <!DOCTYPE html> <html> <head> <meta charset ...
- 零基础逆向工程36_Win32_10_互斥体_互斥体与临界区的区别
1 引言 讲了第二个内核对象,互斥体.前面已经学过一个内核对象,线程.这节讲两个函数,WaitForSingleObject()和WaitForMultipleObjects().因此这两个函数是根据 ...
- 《SQLServer删除重复数据的方法》
方法一: declare @max integer,@id integer open cur_rows fetch cur_rows into @id,@max begin set rowcount ...
- SourceTree 跳过登陆
当前只有Win的版本,Mac自行百度(笑) 很多人用git命令行不熟练,那么可以尝试使用sourcetree进行操作. 然鹅~~sourcetree又一个比较严肃的问题就是,很多人不会跳过注册或者操作 ...