Codeforces758A Holiday Of Equality 2017-01-20 10:08 48人阅读 评论(0) 收藏
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.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string> using namespace std; int a[100005];
int main()
{
int n;
while(~scanf("%d",&n))
{
int mx=-1;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>mx)
mx=a[i];
}
int sum=0;
for(int i=0;i<n;i++)
{
sum+=(mx-a[i]);
}
printf("%d\n",sum);
}
return 0;
}
Codeforces758A Holiday Of Equality 2017-01-20 10:08 48人阅读 评论(0) 收藏的更多相关文章
- C语言基础总结 分类: iOS学习 c语言基础 2015-06-11 10:08 23人阅读 评论(0) 收藏
//欲练此功必先自宫!!! //第一天:C语言的基础 //进制 //2进制, 10进制, 8进制, 16进制 //注:8进制数前加0, 16进制数前加0x ...
- 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏
文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...
- Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 164431 Accepted: ...
- winform timespan 两个时间的间隔(差) 分类: WinForm 2014-04-15 10:14 419人阅读 评论(0) 收藏
TimeSpan 结构 表示一个时间间隔. 先举一个小例子:(计算两个日期相差的天数) 代码如下: DateTime dt = DateTime.Now.ToShortDateString(yyyy ...
- 全面解析sizeof(上) 分类: C/C++ StudyNotes 2015-06-15 10:18 188人阅读 评论(0) 收藏
以下代码使用平台是Windows7 64bits+VS2012. sizeof是C/C++中的一个操作符(operator),其作用就是返回一个对象或者类型所占的内存字节数,使用频繁,有必须对齐有个全 ...
- 欧拉回路-Door Man 分类: 图论 POJ 2015-08-06 10:07 4人阅读 评论(0) 收藏
Door Man Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2476 Accepted: 1001 Description ...
- 山东理工大学第七届ACM校赛-完美素数 分类: 比赛 2015-06-26 10:36 15人阅读 评论(0) 收藏
完美素数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 我们定义:如果一个数为素数,且这个数中含有7或3,那么我们称这个数为完美 ...
- Hangover 分类: POJ 2015-06-11 10:34 12人阅读 评论(0) 收藏
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 108765 Accepted: 53009 Descr ...
- HDU 1532 Drainage Ditches 分类: Brush Mode 2014-07-31 10:38 82人阅读 评论(0) 收藏
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- python-最好大学排名
# -*- coding: utf-8 -*-"""Created on Mon Apr 3 09:37:52 2017 @author: zuihaodaxuepaim ...
- nginx-----惹不起的端口修改
1,查看端口是否被占用 打开CMD,输入输入netstat -aon | findstr :80 出现: TCP 0.0.0.0:80 0.0.0.0:0 ...
- Servlet Request 请求转发
request.getRequestDispatcher("logined.jsp").forward(request, response); //登录用户在登录页面验证通过 ...
- bat cmd dos 通过拖拽参数 上传 截取拖拽上传文件名
echo off setlocal enabledelayedexpansion :: L 小写 for /l %%i in (1,1,10000) do ( :con set /p a= selec ...
- Request method 'GET' not supported
Request method 'GET' not supported 错误原因: GET请求不被允许. 解决方法: 1.从客户端入手.假设浏览器中的js用了ajax发起异步请求GET,将GET改为PO ...
- javaWeb后端学习记录
java后端学习重点: 1.java语言特性: 基础知识,集合,多线程,并发,JVM,NIO,网络编程,设计模式. (★★★★★) jdk源码中有大量的数据结构与java语言细节.jdk源码着重看c ...
- hdoj1087 (DP--LIS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 思路:这题很简单了,纯LIS的解法,没有一点变形,由于数据小,使用O(n^2)LIS解法就足够了 ...
- Python3 open() 函数
Python3 open() 函数 Python3 内置函数 Python open() 方法用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出 ...
- SVN概述
----------------------siwuxie095 SVN 概述 1.SVN 即 Subversion 的 ...
- 关于元表,self,元方法__index
这是需要仔细分辨的几个概念. 元表:相当于table的隐藏属性. 只有固定的一些方法,如__index,__tostring,__add等,称为元方法. 虽然是固定的,但是任何table都可以作为任何 ...