#include<vector>
#include<iostream>
#include<algorithm>
#include"partition.h"
using namespace std;
using ll = long long;
std::vector<int> solve(std::vector<int> A) {
	ll n = A.size();
	ll mn = 1e9, s = 0;
	int mx = 0;
	vector<pair<ll,ll>>v;
	for (ll i = 0; i < n; i++) {
		mx = max(mx, A[i]);
		v.push_back({ A[i],i });
		s += A[i];
	}
	sort(v.begin(), v.end());
	ll l = -1, f = -1;
	for (ll i = 0; i < n; i++) {
		ll sum = 0;
		for (ll j = i; j < n; j++) {
			sum += v[j].first;
			if (sum < (s + 1) / 2 && sum + mx >= (s + 1) / 2 && j != n - 1) {
				ll araj = abs((j - i + 1+1) - (n - (j - i + 2)));
				if (araj < mn) {
					mn = araj;
					l = i;
					f = 1;
				}
			}
			else if (sum >= s) {
				ll araj = abs((j - i + 1) - (n - (j - i + 1)));
				if (araj < mn) {
					mn = araj;
					l = i;
					f = 0;
				}



				break;
			}
		}
	}
	//cout << mn << " " << f << " " << l << endl;
	vector<int>ans;
	if (f == 1) {
		ll sum = 0, r = 0;
		for (ll j = l; j < n; j++) {
			ans.push_back(v[j].second);
			sum += v[j].first;
			if (sum < (s + 1) / 2 && sum + mx >= (s + 1) / 2 && j != n - 1) {
				r = j;
				break;
			}
			
		}
		ans.push_back(v[n - 1].second);
		for (ll j = 0; j < n; j++) {
			if (j < l || (j > r && j < n - 1)) {
				ans.push_back(v[j].second);
			}
		}
	}
	else {
		ll sum = 0, r = 0;
		for (ll j = l; j < n; j++) {
			ans.push_back(v[j].second);
			sum += v[j].first;
			if (sum >= (s + 1) / 2) {
				r = j;
				break;
			}

		}
		for (ll j = 0; j < n; j++) {
			if (j < l || (j > r )) {
				ans.push_back(v[j].second);
			}
		}
	}
		

	
	return ans;
	
}
