#P12366. Digit Sum Sorting
Digit Sum Sorting
Digit Sum Sorting
Little Blue is fascinated by the sum of digits of a number. Today, he wants to sort numbers based on the sum of their digits. The sorting criteria are as follows:
- If two numbers have different digit sums, the one with the smaller digit sum comes first.
- If two numbers have the same digit sum, the smaller numerical value comes first.
For example, since the digit sum of $2022$ is $2+0+2+2=6$ and that of $409$ is $4+0+9=13$, $2022$ comes before $409$. Similarly, $6$ comes before $2022$ because their digit sums are equal ($6$), and $6<2022$.
Given positive integers $n$ and $m$, consider the numbers from $1$ to $n$. If these numbers are sorted according to the above rules, your task is to find the number positioned at the $m$-th place.
inputFormat
The input consists of two positive integers $n$ and $m$ separated by a space, where $1 \le m \le n$.
outputFormat
Output a single integer which is the $m$-th number in the sorted order.
sample
10 5
4