You are given an array of nn integers a1,a2,…,ana1,a2,…,an. After you watched the amazing film "Everything Everywhere All At Once", you came up with the following operation.
In one operation, you choose n−1n−1 elements of the array and replace each of them with their arithmetic mean (which doesn't have to be an integer). For example, from the array [1,2,3,1][1,2,3,1] we can get the array [2,2,2,1][2,2,2,1], if we choose the first three elements, or we can get the array [43,43,3,43][43,43,3,43], if we choose all elements except the third.
Is it possible to make all elements of the array equal by performing a finite number of such operations?
Input
The first line of the input contains a single integer tt (1≤t≤2001≤t≤200) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer nn (3≤n≤503≤n≤50) — the number of integers.
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1000≤ai≤100).
Output
For each test case, if it is possible to make all elements equal after some number of operations, output YESYES. Otherwise, output NONO.
You can output YESYES and NONO in any case (for example, strings yEsyEs, yesyes, YesYes will be recognized as a positive response).
Example
input
Copy
4 3 42 42 42 5 1 2 3 4 5 4 4 3 2 1 3 24 2 22
output
Copy
YES YES NO NO
思路:目的是找有没有一个数是除了他的所有数相加的平均数,当满足这个条件的时候所有数总和的平均值就是这个数,所以我们只需要看所有数的总和的平均数在序列里有没有就行了。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
const int N=200000+10;
typedef long long ll;
int n;
double x,con;
void sove(){
cin>>n;
map<double,int> op;
con=0;
for(int i=0;i<n;i++){
cin>>x;
op[x]++;
con+=x;
}
if(op[con/n]){
printf("YES\n");
}else printf("NO\n");
}
int main(){
int t;
cin>>t;
while(t--){
sove();
}
return 0;
}