#include "partition.h"
#include <bits/stdc++.h>

std::vector<int> solve(std::vector<int> a) {
    int n = a.size();
    int64_t sum = 0;
    std::vector<std::pair<int, int>> b(n);
    std::vector<int> idx(n);
    for (int i = 0; i < n; ++i) b[i] = {a[i], i};
    std::sort(b.begin(), b.end());
    for (int i = 0; i < n; ++i) a[i] = b[i].first, idx[i] = b[i].second;
    for (auto u: a) sum += u;
    int64_t sm = 0, nd = (sum + 1) / 2;
    int l = 0;
    int res = n + 5, optl = -1, optr = -2;
    optl = 0, optr = (n + 1) / 2 - 2;
    for (int i = optl; i <= optr; ++i) sm += a[l];
    while (sm < nd - a.back()) {
        sm -= a[optl++];
        sm += a[++optr];
    }
    std::vector<int> res2;
    for (int i = optl; i <= optr; ++i) res2.emplace_back(idx[i]);
    for (int i = 0; i < optl; ++i) res2.emplace_back(idx[i]);
    for (int i = optr + 1; i < n; ++i) res2.emplace_back(idx[i]);
    return res2;
}
