Source Code
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t; cin >> t;
    while (t--) {
            int n;
            ll sum = 0;
            cin >> n;
            int cnt = n, ind = 0,y=0;
            vector < pair <double, bool> > v(n);
            for (int i = 0; i < n; ++i) {
                double x; cin >> x;
                v[i].first = x;
                sum += x;
                v[i].second = true;
            }
            sort(v.begin(), v.end());
            for (int i = 0; i < n; ++i) {
                double avg = sum / (double)cnt;
                for (int j = ind; j < n; ++j) {
                    if (v[j].first-avg>=0.0) {
                        ind = j;
                        break;
                    }
                    else {
                        v[j].second = false;
                        sum -= v[j].first;
                        cnt--;
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                if (v[i].second) {
                    y++;
                    cout << (ll)v[i].first << ' ';
                }
            }
            if (y == 0)cout << "-1";
        cout << "\n";
    }
    return 0;
}

Copy
To-do List Walaa Abd Elhady
GNU G++17
215 ms
2.6 MB
Accepted