Source Code
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
bool visa[(int)1e6] ;
int main(){
   ios_base::sync_with_stdio(0);cin.tie(0);
   int t ;
   cin >> t ;
   while (t--) {
   		ll n ;
   		long long sum = 0 ;
   		cin >> n;
   		vl x(n);
   		for (auto&i:x) {
   			cin>>i;
   			sum += i ;
   		}
   		int i = 0 ;
   		bool th = true;
   		sort(x.begin(),x.end());
   		while ( th ) {
   			th = false;
   			for (; i < n ;i++) {
   				if ( x[i] < (sum/(n-i)) + (sum%(n-i)?1:0) ) {
   					th = true;
   					sum -= x[i] ;
   				}
   				else {
   					break;
   				}
   			}
   		}
   		for (;i<n;i++) cout << x[i] << " " ;
   		cout << endl;
   }
   return 0;
}
Copy
To-do List SAAD
GNU G++17
133 ms
1.7 MB
Accepted