May address the problem reported by maflcko in #27877#pullrequestreview-1890304914.
For some values, MAX_MONEY - max_spendable - max_output_groups could result in a partial negative value. By putting the addition of group_pos.size() first, all partial results in this line will be strictly positive.
I opened this as a draft, since I was unable to reproduce the issue, so Iām waiting for confirmation whether this in fact mitigates the problem.