CF1543B
分析
要求数列和不变,对数列进行任意操作,求出数列中任意两个数差值的绝对值的和的最小值。我们自然可以想到尽可能地让数值均分,均分过后的数列一定只会有
对于作差,我们也可以进行推导优化。假设均分过后的数列有
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,a[200001];
int sum,op;
signed main(){
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
sum=0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum+=a[i];
}
op=sum%n;
printf("%lld\n",(n-op)*op);
}
}