PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000152. Số nhỏ nhất có các chữ số khác nhau (Minimum Varied Number)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Số nhỏ nhất có các chữ số khác nhau (Minimum Varied Number)
Minimum Varied Number
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Find the smallest positive integer whose decimal digits are pairwise distinct and whose digit sum equals a given integer . Every in the input range has at least one answer.
Input
The input contains one integer .
Output
Print the minimum positive integer with pairwise distinct decimal digits and digit sum .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
20
Output
389
Explanation
The number has digit sum and distinct digits. No one- or two-digit number with distinct digits can have digit sum , and is the smallest feasible three-digit number.