#include "bits/stdc++.h"
#include "partition.h"
// #include "grader.cpp"

using namespace std;

#define SZ(s) (int)s.size()
#define ll long long
#define ff first
#define ss second

vector<int> solve(vector<int> a) {
    int n = SZ(a);
    ll s = 0;
    vector <pair <int, int>> v;
    for(int i = 0; i < n; i++) {
        s += a[i];
        v.push_back({a[i], i});
    }
    sort(v.rbegin(), v.rend());
    ll sm = 0;
    deque <int> p;
    for(auto [i, j] : v) {
        if(sm * 2 >= s) p.push_back(j);
        else p.push_front(j), sm += i;
    }
    return {p.begin(), p.end()};
}
