Problem. ranked pirates split coins. The most senior proposes a split; everyone votes; it passes with at least half the votes (the proposer votes too), otherwise the proposer is thrown overboard and the next one proposes. Pirates want to survive, then maximize coins, then see others thrown overboard (so they vote yes only for a strict improvement).

Answer (backward induction): the proposer buys the cheapest votes, paying each such pirate one coin more than they would get in the -pirate solution. For 5 pirates and 100 coins: .

vector<long long> piratesSplit(int n, long long G) {   // pirate 0 proposes; passes with >= half the votes; returns coins per pirate (needs G large enough)
    vector<long long> cur{G};                           // solution with 1 pirate
    for (int k = 2; k <= n; k++) {
        // cur = split among the k - 1 junior pirates if the proposer dies; buy the cheapest votes
        int need = (k + 1) / 2 - 1;                     // yes votes needed besides the proposer
        vector<int> idx(k - 1); iota(all(idx), 0);
        stable_sort(all(idx), [&](int a, int b) { return cur[a] < cur[b]; });
        vector<long long> nxt(k, 0); long long spent = 0;
        for (int t = 0; t < need; t++) { nxt[idx[t] + 1] = cur[idx[t]] + 1; spent += cur[idx[t]] + 1; }
        nxt[0] = G - spent; cur = nxt;
    }
    return cur;
}