I'm struggling in finding a correct way to approach this, I'm aware that this problem is solvable using dynamic programming, and this problem somehow relates to the "max non-contiguous subarray" problem, yet I cannot make the connection.
Given an array of integers, $A=(a_1,\ldots , a_n)$ for which $\sum_{i=1}^{n}a_i<0$.
A "Positive Interval" is defined to be a pair of indices $(i,j)$, $1\le i\le j\le n$ such that $\sum_{k=i}^{j}a_k>0$
Describe an algorithm to return the minimal size of group $J$ containing positive intervals in such manner that for all $0<a_\ell\in A$, there is (at least) an interval $(i,j)$ in $J$ such that $i\leq\ell\leq j$.
The intervals can be overlapping, and negative numbers of $A$ dont have to take part in any interval of $J$.
For example, given $A=(1,7,-9,2,-10,-5,5,-10,4,-2,3,-1,2)$ , the algorithm should return $2$, since the "optimal" result would be: $$ J=\{(1,4), (7,13)\} $$ where positive interval $(1,4)$ "covers" elements $1,7,-9,2$ while positive interval $(7,13)$ "covers" elements $5,-10,4,-2,3,-1,2$.