Source Code
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
void Fast(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
}
void File() {
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
template<class T> using ordered_set = tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
#define watch(x) cout << (#x) << " = " << x << '\n'
#define endl '\n'
#define all(a)  a.begin(), a.end()
#define fix(n) cout << fixed << setprecision(n)
#define skip continue
const long double pi = acos(-1);
const int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const double EPS = 1e-7;

int main(){
    Fast();
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        deque<int>v(n);
        long double sum = 0;
        for(auto&it:v){
            cin >> it;
            sum += it;
        }
        sort(all(v));
        double average = ceil(sum / n);
        int idx = n;
        while(!v.empty()){
            if(idx == 0)break;
            if(average > v.front()){
                sum -= v.front();
                v.pop_front();
            }
            else{
                average = ceil(sum / (int)v.size());
            }
            idx--;
        }
        if(v.size() == 0){
            cout << -1 << endl;
        }
        else{
            for(auto it : v){
                cout << it << ' ';
            }
            cout << endl;
        }
    }
}
Copy
To-do List Muhamed_Morsi
GNU G++17
135 ms
688 KB
Wrong Answer