A. Holiday Of Equality
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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.

题意:为了公平,最少需要多少福利,每个人都要最多的那个人手里的钱就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 ;
}
A. Holiday Of Equality
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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.

Codeforces 758A Holiday Of Equality的更多相关文章

  1. Codeforces 758A. Holiday Of Equality 贪心

    题目大意: 给定一个长为\(n\)序列,每次操作在一个数上+1,求最小的操作次数使所有的数大小相同. 题解: 对这种题无话可说 #include <cstdio> #include < ...

  2. 【codeforces 758A】Holiday Of Equality

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 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 ...

  4. Codeforces 758A:Holiday Of Equality(水题)

    http://codeforces.com/problemset/problem/758/A 题意:给出n个值,求这里面每个值都要变成最大的那个数,总共需要加上多少. 思路:找出最大的直接算. #in ...

  5. 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 ...

  6. CodeForces758A

    A. Holiday Of Equality time limit per test:1 second memory limit per test:256 megabytes input:standa ...

  7. CodeForces 304C

    E - E Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  8. Codeforces Gym 100187D D. Holidays 排列组合

    D. Holidays Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/D ...

  9. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

随机推荐

  1. Problem02 输出素数

    题目:判断101-200之间有多少个素数,并输出所有素数. 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数. public class ...

  2. oracle count(*) 和count(列)性能

    一直以为oracle中count(列)比count(*) 快,这篇文件解释了一下: http://blog.csdn.net/szstephenzhou/article/details/8446481

  3. Boxes in a Line UVA - 12657 (双向链表)

    题目链接:https://vjudge.net/problem/UVA-12657 题目大意:输入n,m  代表有n个盒子 每个盒子最开始按1~n排成一行  m个操作, 1 x y  :把盒子x放到y ...

  4. 聊一聊IAR的workspace文件组织

    抽空偶尔做个zigbee实验其实也挺好玩的,今天我就来总结一下嵌入式IAR Embedded Workbench这个非常有效的集成开发环境的文件组织. 每一个workspace由一般是由.c文件和一个 ...

  5. web service, wcf, wcf rest, web api之间的区别

    在.NET Framework中,有很多种技术可以创建基于http协议的服务,譬如说web service, wcf,wcf rest和web api等等.网上有很多的文章教我们如何开发.使用这几种技 ...

  6. WEB服务器、网站、域名、IP地址、DNS服务器之间的关系

    域名首先指向你的服务器,这个过程叫解析.  服务器分成好多小块,每小块叫一个空间或者一个虚拟主机.  所以当你输入你的域名以后,服务器收到你域名的访问信息,但不知道要打开这么多个小块中的那一个.所以要 ...

  7. 在线编辑word文档代码

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  8. Linux 启动盘命令

    linux下有很多工具可以制作启动盘, 例如 unetbootin 和 wubi, 不过我们可以使用linux下的一条命令来完成-----dd 操作方法: 1 卸载你的U盘 假设你的u盘对应的设备是s ...

  9. Props 和 IActorRef 3

    在Actor模式中我们使用IActorRef通过ActorSystem来发送消息数据.这么做有两个理由 1.ActorSystem会在消息中封装一些元数据(metadata),这些数据我们可以通过上下 ...

  10. Ajax Jq Razor语句

    1.JS刷新当前页面: window.location.reload(); 2.JSon成功后转向其他页面: window.location.href="要转向页面的地址(一般格式:/页面所 ...