codeforces #392 div2 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.

分析

  补全差价

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;
} 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,868评论 0 23
  • 你决定要走 我又如何去留 天很蓝风很暖 一如当年 你我初见那天 彼时你温文尔雅 彼时我巧笑嫣然 悄然不觉间 一去经...
    且观山海阅读 216评论 0 0
  • 不管是在工作还是生活中,我们总是会制造一些借口,因为找借口是世界上最容易办到的事情之一。谁都会为很多事情找一些借口...
    韩梦娇Taylor阅读 223评论 1 0
  • 即使是在一座城市漂泊, 也要像定居一样去热爱。 去看古城和老街,去逛校园和公园, 拍下流浪的猫,抚摸经过的风和狗。...
    白米饭_阅读 181评论 0 0
  • 体制内的相对自由 来北京刚好一个月了。 除了不太喜欢一起风就嚣张的柳絮和每天干燥无奇的天气外,其他的都还好。 作为...
    u以后阅读 305评论 0 0