Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
1.2 kB
1
Indexable
Never
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n; cin>>n;
        vector<int> v(n);
        int a; int b; int flag = -1; int flag2 = -1;
        for(int i=0; i<n; i++)
        {
            cin>>v[i];
        }
        sort(v.begin(),v.end());
        for(int i=0; i<n; i++)
        {
            if(i==0)
                a = v[i];
            else if(v[i]==a)
                continue;
            else if(flag==-1 && v[i]!=a)
            {
                b = v[i];
                flag = 0;
            }
            else if(v[i]!=a && v[i]!=b)
            {
                cout<<"No"<<endl;
                break;
                flag2 = 0;
            }
        }
        if(flag2==-1)
        {
            int na = (lower_bound(v.begin(),v.end(),a)-v.begin()) - (upper_bound(v.begin(),v.end(),a)-v.begin());
            int nb = (lower_bound(v.begin(),v.end(),b)-v.begin()) - (upper_bound(v.begin(),v.end(),b)-v.begin());
            if(na==nb || na==nb+1)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
    }
}
Leave a Comment