Codeforce---educational codeforces Round 3 Load balancing The Chase

Source: Internet
Author: User

It's my idea to see this question, but it's definitely about the average, but then I don't know what to do.

After reading the great God's coefficient, the original discovery is so simple, but I do not know why must be mean and average plus 1, rather than mean and average minus 1;

Okay, here's the code for the Great God:

#include <iostream> #include <cstdio> #include <algorithm>using namespace Std;int a[100005];int Main ( ) {    int n;scanf ("%d", &n);    for (int i=1;i<=n;i++)        scanf ("%d", &a[i]);    Sort (a+1,a+1+n);    A long long sum = 0;    for (int i=1;i<=n;i++)        sum+=a[i];    int p = sum/n;    int n1 = n-sum%n;    int ans = 0;    for (int i=1;i<=n1;i++)    {        if (p<=a[i]) break;        Ans+=p-a[i];    }    for (int i=n1+1;i<=n;i++)    {        if (a[i]>p) break;        Ans+=p+1-a[i];    }    printf ("%d\n", ans);}

Codeforce---educational codeforces Round 3 Load balancing The Chase

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.