codeforces—— 758A —— oliday Of Equality
来源:互联网 发布:淘宝欢乐逛如何使用 编辑:程序博客网 时间:2024/05/29 18:39
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.
50 1 2 3 4
10
51 1 0 1 1
1
31 3 1
4
112
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>using namespace std;int main(){ int n; while(cin>>n) { int temp,max,ans=0; for(int i=0; i<n; i++) if(!i) cin>>max; else { cin>>temp; if(temp<max) ans+=abs(max-temp); if(temp>max) { ans+=i*(temp-max); max=temp; } } cout<<ans<<endl; } return 0;}
- codeforces—— 758A —— oliday Of Equality
- 【codeforces 758A】Holiday Of Equality
- Codeforces 758A-Holiday Of Equality
- CodeForces 758A Holiday Of Equality
- Holiday Of Equality (Codeforces-758A)
- Codeforces Round #392 (Div. 2) 758A Holiday Of Equality
- A. Holiday Of Equality
- CF-Codeforces Round #392 (Div. 2)-A-Holiday Of Equality
- Codeforces Round #392 (Div. 2) A.Holiday Of Equality
- Codeforces Round #392(Div. 2) A Holiday Of Equality【水题】
- Codeforces Round #392 (Div. 2)A Holiday Of Equality
- 深夜切题——Divisible&Equality
- Codeforces Round #392 (Div. 2) A. Holiday Of Equality(水题)
- CF758 A. Holiday Of Equality (水题)
- CodeForces 3A Shortest path of the king(贪心)——Codeforces Beta Round #3
- Codeforces Round #392 (Div. 2)Holiday Of Equality
- 【打CF,学算法——一星级】Codeforces 699A Launch of Collider (水题)
- Codeforces758A Holiday Of Equality
- 树莓派玩转3g模块
- JavaScript 的函数柯里化
- 手风琴下拉列表
- 1000 A+B
- 信号的表示和处理
- codeforces—— 758A —— oliday Of Equality
- 【Redis深入】配置文件详解
- 老年(已退役)选手复习计划 PART1
- 1002. 写出这个数 (20)
- 手机上拉刷新 angular
- linux curses函数库
- 空悬指针和野指针
- PathEffect,使用mPaint.setPathEffect为path路径设置不同的效果
- zeromq+python安装手册