Source Code
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef long long ll;
#define pb push_back
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        ll ratings[n];
        for(int i=0; i<n; i++) {
            cin >> ratings[i];
        }
        sort(ratings, ratings+n);
        int competitors = count(ratings, ratings+n, ratings[n-1]) - 1;
        if(competitors==0) {
            cout << n << endl;
        } else if (competitors==1) {
            cout << n-1 << endl;
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}
Copy
Proud Competitors osama_o
GNU G++17
47 ms
444 KB
Accepted