#K8906. Smallest Integer With Given Digit Sum
Smallest Integer With Given Digit Sum
Smallest Integer With Given Digit Sum
You are given a positive integer \( N \). Your task is to find the smallest positive integer \( M \) such that:
- The sum of the digits of \( M \) is exactly \( N \); that is, \( \sum_{i} d_i = N \).
- Every digit in \( M \) is non-zero and the digits are in non-decreasing order (i.e. each digit is less than or equal to its subsequent digit).
If no such \( M \) exists, output -1.
Examples:
- For \( N = 5 \), the answer is
5
. - For \( N = 10 \), the answer is
19
(since \( 1 + 9 = 10 \) and 1 < 9). - For \( N = 15 \), the answer is
69
(since \( 6 + 9 = 15 \) and 6 < 9). - For \( N = 50 \), no valid \( M \) exists; hence, output is
-1
.
inputFormat
The input is given from stdin and consists of:
- An integer \( T \) representing the number of test cases.
- \( T \) lines, each containing a single integer \( N \) for which you have to compute the answer.
outputFormat
For each test case, output the smallest positive integer \( M \) satisfying the conditions, or -1 if such an integer does not exist. The answers for each test case should be output on separate lines to stdout.
## sample1
5
5
</p>