Source Code
#include <fstream>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <set>
using namespace std;

int main()
{
    int _;
    cin>>_;
    while (_--)
    {
        long long n,b,mx=0;
        cin>>n;
        vector<long long> ary;
        map<long long, long long> mp;
        for(int i=0; i<n; i++)
        {
            int x;
            cin>>x;
            ary.push_back(x);
            if (mx<ary[i])
                mx=ary[i];
            mp[ary[i]]++;
        }
        sort(ary.begin(),ary.end());
        if(mp[mx]==1)
            cout<<ary.size()<<endl;
        else if(mp[mx]==2)
            cout<<ary.size()-1<<endl;
        else
            cout<<-1<<endl;

    }
}
Copy
Proud Competitors Abbro
GNU G++17
111 ms
2.7 MB
Accepted