CF1543B Customising the Track 题解

· · 题解

简单分析一下:

它说答案要最小,那么往每个数上放就要平均。

肯定不能正好分完,多余的一个一个分。

然后就是较大的数和较小的数的和。

代码

#include<bits/stdc++.h>
using namespace std;
size_t n,t,a[211111];
int main() {
    cin>>t;
    while(t--) {
        int ans=0;
        cin>>n;
        for(int i=1; i<=n; i++) {
            cin>>a[i];
            ans+=a[i];
        }
        int x=n-ans%n;
        int y=ans%n;
        cout<<x*y<<endl;
    }
    return 0;
}