Well, certainly $S=\sum\min(p_i,q_i)$ is an upper bound; the question is whether we can get there. First, we should note that the maximum exists: the set of such matrices is closed, and the trace function is continuous so it achieves its maximum. Now suppose we have one of these matrices of trace strictly less than $S$; we'll show by an old trick that it's not of maximal trace, and this finishes the result. Let $M$ be our matrix. Since $\operatorname{tr} M < S$ there must be some $i$ such that $M_{i,i}<\min(p_i,q_i)$. By the defining conditions of our set of matrices, it follows that there are $j$ and $k$, neither equal to $i$, such that $M_{i,j}>0$ and $M_{k,i}>0$. But then we can replace $M$ by a new matrix in which we increase $M_{i,i}$ and $M_{k,j}$ and decrease $M_{i,j}$ and $M_{k,i}$ all by the same (positive) amount while keeping all entries nonnegative. This resulting matrix has trace strictly larger than $M$, as desired.