Source Code
#include <cstring>
#include <vector>
#include <stdio.h>
#include <bitset>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include<sstream>
#include <iomanip>
#include <vector>
#include<utility>
#include <iostream>
#define ll long long
using namespace std;
int main()
{

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t; cin >> t;
	while (t--) {
		ll x, y; cin >> y;
		vector<ll>v;
		for (int i = 1; i <= y; i++) {
			cin >> x;
			v.push_back(x);
		}
		sort(v.begin(), v.end());
		ll ctr = 0;
		for (int i = y - 2; i >= 0; i--) {
			if (v[y - 1] == v[i]) {
				ctr++;
			}
			else {
				break;
			}
		}
		if (y - ctr == 1&&y!=1) {
			cout << "-1\n";
		}
		else
			cout << y -ctr << "\n";
	}
}
Copy
Proud Competitors makamkh899
GNU G++17
5 ms
312 KB
Wrong Answer