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;
        pair<double,int> arr[n];
        for(int i = 0; i < n; i++){
            cin >> arr[i].first;
            arr[i].second = i;
        }
        reverse(arr, arr + n);
        double sum = 0;
        int ind  = n - 1;
        for(int i = 0 ; i < n; i++){
            sum += arr[i].first;
            if(sum / (i + 1) > arr[i].first){
                ind = i  - 1;
                break;
            }

        }
        vector<pair<int,double>> v;
        for(int i = 0; i <= ind; i++){
            v.push_back({arr[i].second , arr[i].first});
        }
        sort(v.begin() , v.end());
        for(auto x : v) cout << x.second << " ";
        cout << "\n";
    }
    return 0;
}  
Copy
To-do List AbduSaber
GNU G++17
166 ms
1.8 MB
Wrong Answer