Codeforces Round #794 (Div. 2)A. Everything Everywhere All But One

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值