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.

分析

??補(bǔ)全差價

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;
} 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,111評論 0 23
  • 你決定要走 我又如何去留 天很藍(lán)風(fēng)很暖 一如當(dāng)年 你我初見那天 彼時你溫文爾雅 彼時我巧笑嫣然 悄然不覺間 一去經(jīng)...
    且觀山海閱讀 227評論 0 0
  • 不管是在工作還是生活中,我們總是會制造一些借口,因?yàn)檎医杩谑鞘澜缟献钊菀邹k到的事情之一。誰都會為很多事情找一些借口...
    韓夢嬌Taylor閱讀 243評論 1 0
  • 即使是在一座城市漂泊, 也要像定居一樣去熱愛。 去看古城和老街,去逛校園和公園, 拍下流浪的貓,撫摸經(jīng)過的風(fēng)和狗。...
    白米飯_閱讀 208評論 0 0
  • 體制內(nèi)的相對自由 來北京剛好一個月了。 除了不太喜歡一起風(fēng)就囂張的柳絮和每天干燥無奇的天氣外,其他的都還好。 作為...
    u以后閱讀 360評論 0 0

友情鏈接更多精彩內(nèi)容