#K956. Minimal Integer with Given Digit Sum
Minimal Integer with Given Digit Sum
Minimal Integer with Given Digit Sum
Given a non-negative integer \(N\), your task is to find the minimal positive integer \(X\) such that the sum of its digits equals \(N\). If no such integer exists, output \(-1\).
Explanation:
- If \(N = 0\), output \(-1\) because there is no positive integer whose digits sum to zero.
- For a positive \(N\), one can greedily subtract the maximum possible digit (up to 9) at each step and then arrange the collected digits in ascending order to form the smallest possible integer. For example, if \(N = 15\), we take \(9\) then \(6\) and after reordering the digits, the answer is \(69\).
The problem requires you to read an integer from the standard input and produce the result in the standard output.
inputFormat
The input consists of a single integer \(N\) (\(0 \leq N \leq 10^9\)), provided via standard input.
outputFormat
Output a single integer \(X\), the minimal positive integer such that the sum of its digits equals \(N\). If no such integer exists, output \(-1\).
## sample9
9