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. dynamic:动态类型简单用法,写法

    class 动态创建数据 { //动态类型:本质感觉跟object的用法差不多,只是在执行的时候才知道数据类型 public dynamic Dynamic() { //定义一个动态类型,作为返回值 ...

  2. c++从txt中读取数据,数据并不是一行路径(实用)

    #include <iostream>#include <fstream>#include <string> using namespace std; //输出空行 ...

  3. Linux下Java环境安装配置记录

    下载jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 两种安装方式: 第一 ...

  4. my19_mysql 多线程备份恢复工具mydumper

    mydumper适合库中有大表且CPU个数较多的场景,多用于恢复从库或单个实例 推荐用法**************************** mydumper -u automng -p root ...

  5. 使用PyCharm实现远程编写并调试代码

    使用PyCharm实现远程编写并调试代码 版权声明:本文为博主原创文章,转载请注明出https://www.cnblogs.com/wenqiangit/p/9771947.html 因为工作中使用的 ...

  6. 工作中常用到的sql命令!!!

    一.mysql数据库日常操作.     1.启动mysql:/etc/init.d/mysql start (前面为mysql的安装路径)     2.重启mysql:  /etc/init.d/my ...

  7. Checkstyle的配置详解

    Checkstyle是一款检查java程序代码样式的工具,可以有效的帮助我们检视代码以便更好的遵循代码编写标准,特别适用于小组开发时彼此间的样式规范和统一.Checkstyle提供了高可配置性,以便适 ...

  8. ElasticSearch 服务搭建

    一.搭建环境 操作系统:Win7 ElasticSearch:1.73 Java JDK:1.7 二.搭建操作 1.安装Java JDK,然后配置系统环境变量,新建CLASS_PATH(jre所在目录 ...

  9. ST-LINK接口定义

    ST-LINKIII管脚定义及接法:     ST-LINK IIILED灯三种状态含义: 常亮:目标板与ST-LINK在SWIM模式或者JTAG/SWD模式下已经通讯初始化. 闪烁:目标板与ST-L ...

  10. shell中获取本机ip地址

    shell中获取本机ip地址 方法一: /sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr ...