Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
874 B
4
Indexable
Never
#include<iostream>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i = 0; i<t; i++){
        long int n;
        cin>>n;
        long int a[n];
        int max =0;
        int max2 = 0;
        if(n==1){
            long int a;
            cin>>a;
            if(a>1){
                cout<<"NO"<<endl;
            }
            else{
                cout<<"YES"<<endl;
            }
        }
        else{
            for(int j = 0; j<n; j++){
                cin>>a[j];
                if(a[j]>a[max]){
                    max = j;
                }
                if(j!=max){
                    if(a[j]>a[max2]){
                        max2 = j;
                    }
                }
            }
        if((a[max]-a[max2])>1){
            cout<<"NO"<<endl;;
        }
        else{
            cout<<"YES"<<endl;
        }
        }

    }

}