题目:
题解:
cpp
int findMinMoves(int* machines, int machinesSize){
int sum=0;
for(int i=0;i<machinesSize;i++){
sum+=machines[i];
}
if(sum%machinesSize!=0){
return -1;
}
int p=sum/machinesSize;
int ans=0;
int cur=0;
for(int i=0;i<machinesSize;i++){
cur+=(machines[i]-p);
ans=fmax(ans,machines[i]-p);
ans=fmax(ans,abs(cur));
}
return ans;
}