codeforces-1399A-Remove Smallest

4 篇文章 0 订阅
1 篇文章 0 订阅

A. Remove Smallest

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given the array aa consisting of nn positive (greater than zero) integers.

In one move, you can choose two indices ii and jj (i≠ji≠j) such that the absolute difference between aiai and ajaj is no more than one (|ai−aj|≤1|ai−aj|≤1) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).

Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Then tt test cases follow.

The first line of the test case contains one integer nn (1≤n≤501≤n≤50) — the length of aa. The second line of the test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100), where aiai is the ii-th element of aa.

Output

For each test case, print the answer: "YES" if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or "NO" otherwise.

Example

input

Copy

5
3
1 2 2
4
5 5 5 5
3
1 2 4
4
1 3 4 4
1
100

output

Copy

YES
YES
NO
NO
YES

Note

In the first test case of the example, we can perform the following sequence of moves:

  • choose i=1i=1 and j=3j=3 and remove aiai (so aa becomes [2;2][2;2]);
  • choose i=1i=1 and j=2j=2 and remove ajaj (so aa becomes [2][2]).

In the second test case of the example, we can choose any possible ii and jj any move and it doesn't matter which element we remove.

In the third test case of the example, there is no way to get rid of 22 and 44.

题意:每次选两个数,如果这两个数差的绝对值小于等于1,则删掉小的那个,如果相等,则随便删一个,问是否能删剩下一个数。

思路:排序,然后逐个遍历看差是否小于等于1.

ac代码:

#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#define MAXN 100005
using namespace std;
bool cmp(int a,int b){
	return a<b;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		int num[1005];
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>num[i];
		}
		sort(num,num+n,cmp);
		int flag=true;
		for(int i=1;i<n;i++){
			if(!(num[i-1]+1>=num[i])){
				flag=false;
				break;
			}
		}
		if(flag){
			cout<<"YES"<<endl;
		}
		else {
			cout<<"NO"<<endl;
		}
	}
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值