#include <bits/stdc++.h>
#include "partition.h"
using namespace std;
vector<int> solve(vector<int> a)
{
    vector<pair<int,int>>v;
    vector<int>ans;
    int n=a.size();
    long long sum=0,sum1=0;
    for(int i=0;i<n;i++)
    {
        v.push_back({a[i],i});
        sum1+=a[i];
    }
    sort(v.begin(),v.end());
    int res=1e9,res1=-1,k=0;
    for(int i=0;i<n;i++)
    {
        sum+=v[i].first;
        if(sum>=sum1/2+sum1%2)
        {
            while(sum>=sum1/2+sum1%2)
            {
                int temp=n-(i-k+1);
                if(abs(temp-(i-k+1))<res)
                {
                    res1=k;
                    res=abs(temp-(i-k+1));
                }
                sum-=v[k].first;
                k++;
            }
        }
    }
    sum=0;
    for(int i=res1;i<n;i++)
    {
        ans.push_back(v[i].second);
    }
    for(int i=0;i<res1;i++)
    {
        ans.push_back(v[i].second);
    }
    return ans;
}
