Given a finite set $P = \{ p_1, \dots, p_n \} $ of integers, I'd like to split it into two subsets $A = \{ a_1, \dots, a_m \} \subseteq P$ and $B = \{ b_1, \dots, b_r \} \subseteq P$, where $m + r = n$, and, for each subset, the sum of the numbers is as close as possible to half the total of the sum of the numbers in $P$. More precisely, we have the following constraints $$\sum_i^m a_i \leq \left \lceil \frac{\sum_j^n p_j}{2} \right \rceil $$ and $$\sum_i^r b_i \leq \left \lceil \frac{\sum_j^n p_j}{2} \right \rceil $$ and $$\sum_i^m a_i + \sum_i^r b_i \leq \sum_j^n p_j $$
How would I go about doing this in a programmatic way?