提交时间:2023-11-04 11:29:08

运行 ID: 108894

#include<bits/stdc++.h> using namespace std; int n,sum,step,i,j; int a[110]; int main(){ cin>>n; for(i=1;i<=n;i++){ cin>>a[i]; sum+=a[i]; } sum/=n; for(i=1;i<=n;i++){ a[i]-=sum; } i=1,j=n; while(a[i]==0&&i<n){ i++; } while(a[j]==0&&j>1){ j--; } while(i<j){ a[i+1]+=a[i]; a[i]=0; step++; i++; while(a[i]==0&&i<j){ i++; } } cout<<step; return 0; }