codeforces-758a Holiday of equality

Source: Internet
Author: User

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 TR Easury.

Totally in Berland There are N citizens, the welfare of each of them are estimated as the integer in AI burles (Burle is th E currency in Berland).

You are are the Royal Treasurer, which needs to count the minimum charges of the The king's Kingdom. The king can only give, he hasn ' t-a power to take away them. Input

The "The" the "contains" (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. Example Input

5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note

In the ' I example if we add to the ' the ' Citizen 4 Burles, to the second 3, to the third 2 and to the fourth 1, then th E Welfare of all citizens would equal 4.

In the second example it's enough to give one burle to the third.

In the third example it's necessary to give two burles to the "the" and "third citizens to" the welfare of citizen s equal 3.

In the fourth example it are possible to give nothing to everyone because all citizens have.


#include <iostream>
#include <cstdio>
#include <algorithm>
int num[105];
using namespace std;

int main ()
{
    int n;
    scanf ("%d", &n);
    for (int i = 0; i < n; i++)
        scanf ("%d", &num[i]);
    Sort (num, num + N);
    int sum = 0;
    for (int i = 0; i < n-1 i++)
        sum + = num[n-1]-num[i];
    cout << sum << endl;
    return 0;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.