提交时间:2023-11-04 11:22:43

运行 ID: 108872

#include<bits/stdc++.h> using namespace std; int a[10005]; int main() { int n; cin >> n; int sum = 0; for(int i = 1;i <= n;i++) { cin >> a[i]; sum += a[i]; } int cnt = 0; int jun = sum / n; for(int i = 1;i <= n - 1;i++) { if(a[i] < jun) { int cha = jun - a[i]; a[i + 1] = a[i + 1] - cha; a[i] = jun; cnt++; } else if(a[i] > jun) { int cha = a[i] - jun; a[i + 1] = a[i + 1] + cha; a[i] = jun; cnt++; } } cout << cnt; return 0; }