提交时间:2019-12-15 18:44:05
运行 ID: 3311
#include<bits/stdc++.h> using namespace std; int main(){ int n,ave,step,a[100000],i,j; cin>>n; ave=0;step=0; for (i=1;i<=n;++i){ cin>>a[i]; ave+=a[i]; } ave/=n; for (i=1;i<=n;++i) a[i]-=ave; 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<<endl; }