Source Code
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef long long int ll;

ll mod=1e9+7;
ll a[300010];
ll c[300010];

ll tc,i,j,k,n,m;
string s,s1,s2;

map<ll,ll> mp;

int main(){
    IOS

    cin>>tc;
    while(tc--){

            cin>>n;
            ll s=0;
            for(i=0;i<n;i++){
                cin>>a[i];
                s+=a[i];
            }

            ll avg=ceil(s/(double)n);

            ll all=n;

            ll pres=s;
            bool ok=1;

            while(ok){
                    for(i=0;i<n;i++)
                    if(a[i]<avg && a[i]!=-1){
                        s-=a[i];
                        a[i]=-1;
                        all--;
                    }

                    avg=ceil(s/(double)all);

                    if(s==pres)
                        ok=0;
                    else
                        pres=s;
            }


            for(i=0;i<n;i++)
                if(a[i]!=-1)
                cout<<a[i]<<' ';

            cout<<endl;
    }

}
Copy
To-do List AshcoOoOdel
GNU G++17
86 ms
1.6 MB
Accepted