Minimum  Varied Number (Codeforces 1714C)
Tags: Greedy, greedy

Find the minimum number with the given sum of digits $$$s$$$ such that all digits in it are distinct (i.e. all digits are unique).For example, if $$$s=20$$$, then the answer is $$$389$$$. This is the minimum number in which all digits are different and the sum of the digits is $$$20$$$ ($$$3+8+9=20$$$).For the given $$$s$$$ print the required number.

Input: The first line contains an integer $$$t$$$ ($$$1 \le t \le 45$$$) — the number of test cases.Each test case is specified by a line that contains the only integer $$$s$$$ ($$$1 \le s \le 45$$$).

Output: Print $$$t$$$ integers — the answers to the given test cases.


Sample Inputs:
4
20
8
45
10

Sample Outputs:
389
8
123456789
19

Solution (Python):
for t in range(int(input())):
    x = int(input())
    s = ''
    for i in range(9, 0, -1):
        if x - i == abs(x - i):
            x -= i
            s += str(i)
    print(s[::-1])

Solution (Python):
for i in range(int(input())):
    x = int(input())
    s = ''
    for i in range(9, 0, -1):
        if x - i == abs(x - i):
            x = x - i
            s = str(i) + s
    print(s)

Solution (Python):
t = int(input())
for i in range(t):
    num = int(input())
    reverse = ''
    sum1 = 0
    while sum1 != num:
        digits = '987654321'
        for x in digits:
            if sum1 + int(x) > num:
                digits = digits[digits.index(x) + 1:len(digits)]
            else:
                digits = digits[digits.index(x) + 1:len(digits)]
                reverse += str(x)
                sum1 += int(x)
    real = ''
    for y in range(-1, -1 * (len(reverse) + 1), -1):
        real += reverse[y]
    print(int(real))