// 3桁を全探索すればいいか use proconio::{fastout, input}; #[fastout] fn main() { input! { t: usize } for _ in 0..t { let ans = solve(); println!("{ans}"); } } fn solve() -> String { input! { k: usize } let mut cand = vec![]; for a in 0..10 { for b in 0..10 { for c in 0..10 { if a <= b + c || a + b + c > k { continue; } let rest = k - a - b - c; let (q, r) = (rest / 9, rest % 9); let nines = std::iter::repeat_n('9', q).collect::(); let r = if r == 0 { String::new() } else { r.to_string() }; cand.push(format!("{a}{b}{c}{r}{nines}")); cand.push(format!("{r}{a}{b}{c}{nines}")); } } } cand.sort_unstable_by(|a, b| a.len().cmp(&b.len()).then(a.cmp(b))); cand[0].clone() }