Nonnegative real numbers $p_{1},\ldots,p_{n}$ and $q_{1},\ldots,q_{n}$ are such that $p_{1}+\cdots+p_{n}=q_{1}+\cdots+q_{n}$
Among all the matrices with nonnegative entries having $p_i$ as sum of the $i$-th row's entries and $q_j$ as sum of the $j$-th column's entries, find the maximum sum of the entries on the main diagonal.
1. **Define the problem and notation:**
   We are given nonnegative real numbers \( p_1, p_2, \ldots, p_n \) and \( q_1, q_2, \ldots, q_n \) such that 
   \[
   \sum_{i=1}^n p_i = \sum_{j=1}^n q_j.
   \]
   We need to find the maximum sum of the entries on the main diagonal of a matrix \( M \) with nonnegative entries, where the sum of the entries in the \( i \)-th row is \( p_i \) and the sum of the entries in the \( j \)-th column is \( q_j \).

2. **Upper bound for the trace:**
   Consider the sum \( S = \sum_{i=1}^n \min(p_i, q_i) \). This is an upper bound for the trace of any such matrix \( M \) because the diagonal entry \( M_{i,i} \) cannot exceed \( \min(p_i, q_i) \) for each \( i \).

3. **Existence of the maximum:**
   The set of matrices with the given row and column sums is closed and bounded in the space of \( n \times n \) matrices with nonnegative entries. Since the trace function is continuous, it achieves its maximum on this set.

4. **Constructing a matrix with maximum trace:**
   Suppose we have a matrix \( M \) with trace strictly less than \( S \). We will show that this matrix is not of maximal trace by constructing another matrix with a larger trace.

5. **Improving the trace:**
   If \( \operatorname{tr}(M) < S \), there exists some \( i \) such that \( M_{i,i} < \min(p_i, q_i) \). By the conditions on the row and column sums, there must be indices \( j \) and \( k \) (neither equal to \( i \)) such that \( M_{i,j} > 0 \) and \( M_{k,i} > 0 \).

6. **Adjusting the matrix:**
   We can construct a new matrix \( M' \) by increasing \( M_{i,i} \) and \( M_{k,j} \) by a small positive amount \( \epsilon \), and decreasing \( M_{i,j} \) and \( M_{k,i} \) by the same amount \( \epsilon \). This adjustment keeps all entries nonnegative and preserves the row and column sums.

7. **Increasing the trace:**
   The new matrix \( M' \) has a trace given by
   \[
   \operatorname{tr}(M') = \operatorname{tr}(M) + \epsilon,
   \]
   which is strictly larger than the trace of \( M \). This contradicts the assumption that \( M \) had the maximum trace.

8. **Conclusion:**
   Therefore, the matrix with the maximum trace must have \( \operatorname{tr}(M) = S \). Hence, the maximum sum of the entries on the main diagonal is \( \sum_{i=1}^n \min(p_i, q_i) \).

The final answer is \( \boxed{\sum_{i=1}^n \min(p_i, q_i)} \).