Source Code
#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;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template <class __set_element_type>
using gnu_set = tree<__set_element_type, null_type, less<__set_element_type>, rb_tree_tag, tree_order_statistics_node_update>;
template <class __key_type, class __val_type>
using gnu_map = tree<__key_type, __val_type, less<__key_type>, rb_tree_tag, tree_order_statistics_node_update>;

#define ios                  \
    ios::sync_with_stdio(0); \
    cin.tie(0)

const ll oo = 1e18;
const ll MOD = 1e9 + 7;

int t, n;

void solve() {
    cin >> n;
    vector<ll> vec(n);
    for(auto &v: vec)
        cin >> v;
    ll sum = 0;
    for(auto v: vec)
        sum += v;

    ll avg = sum / n + ll(sum % n != 0);
    int idx = 0, cnt = n;
    while(vec[idx] < avg) {
        idx++;
        cnt--;
        sum -= vec[idx-1];
        
        if(idx == n) break;
        if(vec[idx] >= avg) { 
            avg = sum / cnt + ll(sum % cnt != 0);
        }
    }
    if(cnt == 0)
        cout << -1;
    
    for(; idx < n; idx++)
        cout << vec[idx] << ' ';
    cout << '\n';
}

int main() {
    ios;
    cin >> t;
    while(t--) solve();
}
Copy
To-do List Ammar Abu Yaman
GNU G++17
140 ms
5.8 MB
Wrong Answer