Codeforces Round #392 (Div. 2) A、B之我是zz
来源:互联网 发布:qq记牌器源码 编辑:程序博客网 时间:2024/05/17 05:10
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 <cstring>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;const int maxn = 1e6;long long save[maxn];int main(){ int n; long long ans=0; scanf("%d",&n); int i; long long maxx = -1; for(i=1;i<=n;i++){ scanf("%I64d",&save[i]); maxx = max(maxx,save[i]); } for(i=1;i<=n;i++){ ans += maxx-save[i]; } printf("%I64d\n",ans); return 0;}
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <map>using namespace std;string save[30]={"RBYG","RBGY","RYBG","RYGB","RGBY","RGYB","BRYG","BRGY","BYRG","BYGR","BGRY","BGYR","YRBG","YRGB","YBGR","YBRG","YGRB","YGBR","GRBY","GRYB","GBRY","GBYR","GYRB","GYBR"};string ori[30];void init(){ int i,j=-1,k; string now; for(i=1;i<=24;i++){ now.clear(); for(j=1;j<=35;j++){ now += save[i-1]; } ori[i] =now; }}string in;int len;int check(int x){ int i,j; bool flag = true; for(i=0;i<10;i++){ for(j=0;j<len;j++){ if(in[j]!='!'&&in[j]!=ori[x][i+j]){ flag = false; } } if(flag){ return i; } } return -1;}map<char,int> change;int main(){ init(); int i,j; cin>>in; change.clear(); len = in.length(); int add; for(i=1;i<=24;i++){ add = check(i); if(add!=-1){ for(j=0;j<len;j++){ if(in[j]=='!'){ change[ori[i][add+j]]++; } } printf("%d %d %d %d\n",change['R'],change['B'],change['Y'],change['G']); return 0; } } return 0;}
- Codeforces Round #392 (Div. 2) A、B之我是zz
- Codeforces Round #392 (Div. 2) A+B
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #216 (Div. 2) A.B
- Codeforces round #236Div.2--A;B
- Codeforces Round #236 (Div. 2)------A,B
- Codeforces Round #237 (Div. 2) A & B
- Codeforces Round #247 (Div. 2) A B
- Codeforces Round #251 (Div. 2) A~B
- Codeforces Round #249 (Div. 2) A B
- Codeforces Round #271 (Div. 2)-A.B
- Codeforces Round #202 (Div. 2) A,B
- Codeforces Round #277 (Div. 2) A B
- Codeforces Round #278 (Div. 2) A B
- Codeforces Round #278 (Div. 2) A, B
- Codeforces Round #281 (Div. 2) A B
- Codeforces Round #283 (Div. 2) A B
- SecureCRT连接服务器教程(by Sessions)
- (四十九)socket编程——网络套接字函数及建立C/S模型(TCP)
- Spring Security 4 Hello World XML Example(1)
- Shell echo命令
- vld使用
- Codeforces Round #392 (Div. 2) A、B之我是zz
- html:特殊符号
- 使用Redis模拟简单分布式锁,解决单点故障的问题
- 404问题可能的原因
- gtest Test_F 和Test 区别
- Mapreduce中分布式缓存的使用注意点
- 发现了一个挺好用的LoadingLayout,网络错误,无数据,动态显示!
- “QApplication”: No such file or directory
- Nginx实现七层负载均衡配置指导