Given two sets $A = \{a_1, a_2, \dots, a_n\}$ and $B = \{b_1, b_2, \dots, b_n\}$, both consist of positive numbers, this problem is to find a subset $S$ in $\{1, 2, \dots, n\}$ to maximize $$ \left(\sum_{i \in S} a_i\right)\left(\sum_{i \notin S} b_i\right) $$
A naive solution is to iterate over the powerset of $\{1, 2, \dots ,n\}$ and find the maximum value, which is $O(n2^n)$. How to use dynamic programming to solve this?
Any comments would be appreciated.