It is clear the rectangles must be piled up, with the first resting on the side $AB$, the next resting on the first, and so on. If the $n$ rectangles have the lengths of their non-parallel with $AB$ sides equal to $x_1,x_2,\ldots,x_n$, adding to $0\leq \sum_{k=1}^n x_k = x \leq h$, then the sum of the areas of the rectangles can be easily computed to be $\dfrac {a} {h} \left (h\sum_{k=1}^n x_k - \sum_{k=1}^n x_k^2 - \sum_{1\leq i < j \leq n}^n x_ix_j \right ) = \dfrac {a} {2h} \left (2h\sum_{k=1}^n x_k - \sum_{k=1}^n x_k^2 - \left (\sum_{k=1}^n x_k \right )^2 \right ) $. By various methods (the most direct is by Lagrange multipliers), the maximum of this expression is found to be $\dfrac {a} {2nh} x(2nh - (n+1)x)$, occuring for $x_1=x_2=\cdots =x_n = x/n$. In turn, this expression is maximal for $x=\dfrac {n} {n+1} h$, when it takes the value $\dfrac {n} {n+1} \cdot \dfrac {ah} {2} = \dfrac {n} {n+1} \operatorname{area}(\triangle ABC)$.