CF758A.Holiday Of Equality

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 a__i 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.

在贝尔兰,今天是“平等节”。为了庆祝这一节日,国王决定动用国库资金,使贝尔兰所有公民的福利水平完全相等。

贝尔兰共有 nn 位公民,每位公民的福利水平用整数 aia_i(单位:布尔——贝尔兰的货币单位)表示。

你身为皇家财政大臣,需要计算国王为实现这一目标所需发放的最小金额。国王只能向公民发放金钱,而不能从他们手中收回任何款项。

输入格式

The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.

The second line contains n integers _a_1, _a_2, ..., a__n, where a__i (0 ≤ a__i ≤ 106) — the welfare of the i-th citizen.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 表示王国中公民的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n,其中 aia_i(0≤ai≤1060 \leq a_i \leq 10^6)表示第 ii 位公民的福利水平。

输出格式

In the only line print the integer S — the minimum number of burles which are had to spend.

在唯一的一行中输出整数 S —— 所需花费的 burles 的最小数量。

输入输出样例

  • 输入#1

    5
    0 1 2 3 4

    输出#1

    10
  • 输入#2

    5
    1 1 0 1 1

    输出#2

    1
  • 输入#3

    3
    1 3 1

    输出#3

    4
  • 输入#4

    1
    12

    输出#4

    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.

在第一个例子中,如果我们给第一位市民 4 卢布,第二位市民 3 卢布,第三位市民 2 卢布,第四位市民 1 卢布,则所有市民的福利都将等于 4。

在第二个例子中,只需给第三位市民 1 卢布即可。

在第三个例子中,需要给第一位和第三位市民各 2 卢布,才能使所有市民的福利都等于 3。

在第四个例子中,可以不给任何人任何卢布,因为所有市民都已有 12 卢布。

输入解题思路,AI测评打分。不知道怎么写?

首页