forwhat00  
A. Remove Smallest

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).

你一次可以选择任意两个数,如果其差值在1以内,则删除小的数

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.

你的工作就是去看能否靠这种操作将所有的数删得只剩1个。

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.

 

 

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define DEBUG if(1)
#define MAXN 100
#define REP(i,b,e) for(int i=b;i<e;i++)
int list[MAXN],ln;
int main(){
    int CASE;cin>>CASE;
    while(CASE--){
        cin>>ln;
        REP(i,0,ln)cin>>list[i];
    //总之前面的就是基础输入
        int flag=1;
        sort(list,list+ln);
        int lst=list[0];
        REP(i,0,ln){
            if(list[i]-lst>=2){
                flag=0;break;
            }else{lst=list[i];}
//排序后,检查所有相邻的数,存在相邻的相差大于1,则NO
        }
        cout<<(flag?"YES":"NO")<<endl;
    }

    return 0;
}
    

 

posted on 2020-08-09 21:41  forwhat00  阅读(1)  评论(0)    收藏  举报