Source Code
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define		_Narutoo ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define		all(a) a.begin(), a.end()
#define		rall(a) a.rbegin(), a.rend()
#define		endl "\n"
#define		ll long long
#define		uniquee(v) v.resize(unique(v.begin(),v.end())-v.begin())
ll      	OO = 1073741824;
ll gcd(ll x, ll y) { return(!y ? x : gcd(y, x%y)); }
ll lcm(ll x, ll y) { return x / gcd(x, y)*y; }
void File() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	_Narutoo;
	File();
	ll t = 1;
	cin >> t;
	while (t--)
	{
		ll n,sum=0,x;
		cin >> n;
		priority_queue<ll, vector <ll>, greater<ll>>pr;
		for (int i = 0; i < n; i++)
		{
			cin >> x;
			pr.push(x);
			sum += x;
		}
		while (1)
		{
			bool bola = 1;
			double avg = (double)sum / (double)pr.size();
			//cout << avg << endl;
			while (!pr.empty() && pr.top() < avg)
			{
				sum -= pr.top();
				pr.pop();
				bola = 0;
			}
			if (bola)break;
		}
		if (pr.empty())cout << -1 << endl;
		else {
			while (!pr.empty())
			{
				cout << pr.top() << " ";
				pr.pop();
			}
		}
		cout << endl;
	}
}
Copy
To-do List ZyadBahaa
GNU G++17
160 ms
2.6 MB
Accepted