提交时间:2023-11-04 11:33:20
运行 ID: 108905
#include<iostream> using namespace std; const int inf = 1e9; int a[110], b[110], sum = 0, n, ans1 = 0, ans2 = 0; int main(){ cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; b[i] = a[i]; sum += a[i]; } sum /= n; for(int i = 0; i < n - 1; i++){ if(a[i] + a[i+1] < sum){ ans1 = inf; break; } if(a[i] != sum) ans1++; a[i+1] = sum - a[i]; a[i] = sum; } for(int i = n - 1; i >= 1; i--){ if(b[i] + b[i-1] < sum){ ans2 = inf; break; } if(b[i] != sum) ans2++; b[i-1] = sum - b[i]; b[i] = sum; } cout << min(ans1, ans2); return 0; }