提交时间:2023-11-04 10:49:33
运行 ID: 108775
#include<bits/stdc++.h> using namespace std; struct node { int ans; }a[10005]; bool cmp (node x , node y) { return x.ans < y.ans; } int main() { int n; cin >> n; int sum = 0; for(int i = 1;i <= n;i++) { cin >> a[i].ans; sum += a[i].ans; } int cnt = 0; int jun = sum / n; sort(a + 1 , a + n + 1, cmp); for(int i = 1;i <= n - 1;i++) { if(a[i].ans < jun) { int cha = jun - a[i].ans; a[i + 1].ans = a[i + 1].ans - cha; a[i].ans = jun; cnt++; } else if(a[i].ans > jun) { int cha = a[i].ans - jun; a[i + 1].ans = a[i + 1].ans + cha; a[i].ans = jun; cnt++; } } cout << cnt; return 0; }