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.
分析
补全差价
ac代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
using namespace std;
const int maxn = 1e2 + 5;
int a[maxn], n;
int main(){
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d", a + i);
}
int sum = 0, maxa = 0;
for(int i = 0; i < n; ++i){
maxa = max(maxa, a[i]);
}
for(int i = 0; i < n; ++i){
sum += (maxa - a[i]);
}
cout << sum << endl;
return 0;
}