C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
int n;
const int N = 1e4 + 10;
int a[N],res,sum,ave;
int main(){
cin >> n;
for(int i = 1;i <= n;i ++){
cin >> a[i];
sum = sum + a[i];
}
ave = sum / n;
for(int i = 1;i <= n;i ++){
if(a[i] > ave)res = res + a[i] - ave;
}
cout << res;
return 0;
}