We are given positive integer $m$ and non-negative integer $s$, with $1 \leq m \leq 100$ and $0 \leq s \leq 900$, and we need to find the largest of the numbers with length $m$ and sum of individual digits $s$. It is possible that no solution exists, in which case we are to print $\t{-1 -1}$.
We can see that the smallest possible will always have a $1$ in the most significant position; if there is room left in our capacity $m$ digits, take $1$ off the back, append $0$'s, then re-add the $1$. This, reversed, is the smallest possible number with $m$ digits, and digit-sum $s$.
In the code below, notice where we declare array $B$ as a copy of $A$ after the first pass to pull out the digits, but before we modified the result optimistically to get the minimum. From here, we are already in descending order, just need to append $0$'s if fewer than $m$ elements in $B$.