题解
找出大于对应平均数的部分。。。
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=114514;
ll a[100006];
void solve()
{
ll n;
cin>>n;
ll sum=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
sort(a+1,a+1+n);
ll cnt=(sum-1LL)%n+1LL;
ll ave=sum/n+(sum%n!=0);
ll ans=0;
for(int i=n;i>=n-cnt+1;i--)
{
if(a[i]>ave)
{
ans+=a[i]-ave;
}
}
ave-=(sum%n!=0);
for(int i=n-cnt;i>=1;i--)
{
if(a[i]>ave) ans+=a[i]-ave;
}
cout<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
标签:Load,cnt,int,ll,Balancing,ans,ave,sum
From: https://www.cnblogs.com/pure4knowledge/p/18305329