Source Code
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
const int mod = 1e9 + 7;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        double arr[n];
        for(int i = 0; i < n; i++) cin >> arr[i];
        sort(arr, arr + n);
        reverse(arr, arr + n);
        double sum = 0;
        int ind  = n - 1;
        for(int i = 0 ; i < n; i++){
            sum += arr[i];
            if(sum / (i + 1) > arr[i]){
                ind = i  - 1;
                break;
            }

        }
        for(int i = 0; i <= ind; i++) cout << arr[i] << " ";
        cout << "\n";
    }
    return 0;
}  
Copy
To-do List AbduSaber
GNU G++17
196 ms
1.1 MB
Wrong Answer