Ideas:
Solution 1:
because of the small data range, it can be simulated directly.
Method 2:
For each location, the number of required output T is necessary to add the number to the right, to the required output frequency and the left output (I prefix and calculation),
as a topic that can select any number of operating units moving, so take the T max is the answer
code (Method 2):
#include<bits/stdc++.h>
using namespace std;
const int maxm=105;
int a[maxm];
int sum[maxm];
signed main(){
int T;
cin>>T;
while(T--){
int n;
cin>>n;
int tot=0;
for(int i=1;i<=n;i++){
cin>>a[i];
tot+=a[i];
}
if(tot%n){
cout<<-1<<endl;
continue;
}
int av=tot/n;
for(int i=1;i<=n;i++){
sum[i]=sum[i-1]+av-a[i];
}
int ans=0;
for(int i=1;i<=n;i++){
int t=0;
if(sum[i-1]>0)t+=sum[i-1];
if(sum[n]-sum[i]>0)t+=sum[n]-sum[i];
ans=max(ans,t);
}
cout<<ans<<endl;
}
return 0;
}
//http://oj.ecustacm.cn/problem.php?id=2003