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

std::vector<int> solve(std::vector<int> A) {

    const int N = A.size();
    double S = 0;

    std::vector<int> answer(N);
    for (int i = 0; i < N; i++) {
        answer[i] = i;
        S += A[i];
    }

    std::vector<int> bestAnswer;
    int bestResult = INT_MAX;

    do {

        int result = 0;
        double total = 0;

        for (const int &idx : answer) {
            total += A[idx];
            result++;

            if (total >= S / (double)2) {
                break;
            }
        }

        int a = abs((N - result) - result);

        if (a < bestResult) {
            bestResult = a;
            bestAnswer = answer;
        }

    } while (std::next_permutation(answer.begin(), answer.end()));

    return bestAnswer;
}
