#include "partition.h"
#include<bits/stdc++.h>
using namespace std;

std::vector<int> solve(std::vector<int> a) {
    int n = a.size();
    vector<int> ans(0);
    pair<int,int> big = {-1,-1};
    for(int i = 0; i < n; i++) {
        big = max(big,{a[i],i});
    }
    int sb = 0;
    int p = 0;
    while(p < n-1) {
        int x = p,y = p+1;
        if(x == big.second) {
            x++;
            y++;
        }
        else if(y == big.second) {
            y++;
        }
        if(y == n-1) {
            break;
        }
        int dif = a[y]-a[x];
        if((dif < 0 && sb > 0) || (dif < 0 && sb > 0)) {
            sb+=dif;
            ans.push_back(x);
        }
        else {
            sb-=dif;
            ans.push_back(y);
        }
        p = y+1;
    }
    vector<bool> yo(n,true);
    for(int v: ans) {
        yo[v] = false;
    }
    for(int i = 0; i < n; i++) {
        if(yo[i]) {
            ans.push_back(i);
        }
    }
    return ans;
}
