当前位置: 首页 > news >正文

Codeforces 758A Holiday Of Equality

题目链接:http://codeforces.com/problemset/problem/758/A
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了。

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int maxn = 1000000 + 5;
 6 
 7 int n;
 8 int a[maxn];
 9 
10 int main()
11 {
12 
13     scanf("%d",&n);
14     int mmax = -1;
15     for(int i=0;i<n;i++) {
16         scanf("%d",&a[i]);
17         mmax = max(mmax,a[i]);
18     }
19 
20     int sum = 0;
21     for(int i=0;i<n;i++) {
22         sum += (mmax-a[i]);
23     }
24 
25     printf("%d\n",sum);
26 
27     return 0;
28 }

 

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.

转载于:https://www.cnblogs.com/TreeDream/p/6322650.html

相关文章:

  • redhat配置caffe
  • CCF201312-1 出现次数最多的数(100分)
  • 如何在Flutter工程中添加Android AAR文件
  • Confluence-企业知识管理与协同软件安装步骤
  • Mac下关闭Sublime Text 3的更新检查
  • AngularJS实现跨域请求
  • 云计算学习(3-3)云计算的由来-应运而生
  • 1095. Cars on Campus (30)
  • Java之戳中痛点 - (1)易变业务使用脚本语言编写
  • CENTOS查看系统磁盘使用情况
  • PHP.ini配置文件(转载)
  • ie中存在的兼容问题及解决办法
  • Elasticstack 5.1.2 集群日志系统部署及实践
  • Roslyn如何实现简单的代码提示
  • 计划
  • [分享]iOS开发 - 实现UITableView Plain SectionView和table不停留一起滑动
  • [译] 理解数组在 PHP 内部的实现(给PHP开发者的PHP源码-第四部分)
  • Angular4 模板式表单用法以及验证
  • Apache的80端口被占用以及访问时报错403
  • Hibernate最全面试题
  • JavaScript工作原理(五):深入了解WebSockets,HTTP/2和SSE,以及如何选择
  • Material Design
  • React Transition Group -- Transition 组件
  • use Google search engine
  • 电商搜索引擎的架构设计和性能优化
  • 机器学习 vs. 深度学习
  • 入门到放弃node系列之Hello Word篇
  • 网络应用优化——时延与带宽
  • 吴恩达Deep Learning课程练习题参考答案——R语言版
  • 小程序开发中的那些坑
  • 学习笔记:对象,原型和继承(1)
  • 正则表达式
  • 正则与JS中的正则
  • hi-nginx-1.3.4编译安装
  • Nginx实现动静分离
  • ​力扣解法汇总946-验证栈序列
  • ​软考-高级-信息系统项目管理师教程 第四版【第14章-项目沟通管理-思维导图】​
  • #数学建模# 线性规划问题的Matlab求解
  • #我与Java虚拟机的故事#连载09:面试大厂逃不过的JVM
  • #我与Java虚拟机的故事#连载11: JVM学习之路
  • $.proxy和$.extend
  • (1)(1.11) SiK Radio v2(一)
  • (2020)Java后端开发----(面试题和笔试题)
  • (33)STM32——485实验笔记
  • (八)Flask之app.route装饰器函数的参数
  • (八)五种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (学习日记)2024.03.25:UCOSIII第二十二节:系统启动流程详解
  • * 论文笔记 【Wide Deep Learning for Recommender Systems】
  • .NET Core Web APi类库如何内嵌运行?
  • .net core 连接数据库,通过数据库生成Modell
  • .NET delegate 委托 、 Event 事件
  • .Net Framework 4.x 程序到底运行在哪个 CLR 版本之上
  • .NET 反射的使用
  • .Net 知识杂记
  • .sdf和.msp文件读取